UNPKG

@livingroot/yandex-metrica-ab-react

Version:
24 lines (23 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useExperiments = void 0; const react_1 = require("react"); const createSnippet_1 = require("./createSnippet"); const useExperiments = (params) => { const { clientId, clientFeatures, config = {}, param: i } = params; const [data, setData] = (0, react_1.useState)({ ready: false, flags: {} }); const href = window.location.href; (0, react_1.useEffect)(() => (0, createSnippet_1.createSnippet)(), []); (0, react_1.useEffect)(() => { const enableVisual = typeof config.enableVisual === 'undefined' || config.enableVisual; window.ymab({ clientId, clientFeatures, config: Object.assign(Object.assign({}, config), { enableWatch: typeof config.enableWatch === 'undefined' ? enableVisual : config.enableWatch }), i, callback: (data) => setData(Object.assign(Object.assign({}, data), { ready: true })), }); }, [clientId, clientFeatures, i, href]); return data; }; exports.useExperiments = useExperiments;