@easyfunnel/react 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -70,7 +70,7 @@ function EasyFunnelProvider(_a) {
70
70
  "children",
71
71
  "config"
72
72
  ]);
73
- const trackerRef = (0, import_react.useRef)(null);
73
+ const [tracker, setTracker] = (0, import_react.useState)(null);
74
74
  (0, import_react.useEffect)(() => {
75
75
  if (!options.apiKey) {
76
76
  console.error(
@@ -78,19 +78,17 @@ function EasyFunnelProvider(_a) {
78
78
  );
79
79
  return;
80
80
  }
81
- if (!trackerRef.current) {
82
- trackerRef.current = import_sdk.EasyFunnel.init(__spreadProps(__spreadValues({}, options), {
83
- autoPageView: true,
84
- rules: config == null ? void 0 : config.rules
85
- }));
86
- }
81
+ const instance = import_sdk.EasyFunnel.init(__spreadProps(__spreadValues({}, options), {
82
+ autoPageView: true,
83
+ rules: config == null ? void 0 : config.rules
84
+ }));
85
+ setTracker(instance);
87
86
  return () => {
88
- var _a2;
89
- (_a2 = trackerRef.current) == null ? void 0 : _a2.destroy();
90
- trackerRef.current = null;
87
+ instance.destroy();
88
+ setTracker(null);
91
89
  };
92
90
  }, [options.apiKey]);
93
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EasyFunnelContext.Provider, { value: trackerRef.current, children });
91
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EasyFunnelContext.Provider, { value: tracker, children });
94
92
  }
95
93
  function useEasyFunnel() {
96
94
  return (0, import_react.useContext)(EasyFunnelContext);
package/dist/index.mjs CHANGED
@@ -35,7 +35,7 @@ import {
35
35
  createContext,
36
36
  useContext,
37
37
  useEffect,
38
- useRef
38
+ useState
39
39
  } from "react";
40
40
  import { EasyFunnel } from "@easyfunnel/sdk";
41
41
  import { jsx } from "react/jsx-runtime";
@@ -48,7 +48,7 @@ function EasyFunnelProvider(_a) {
48
48
  "children",
49
49
  "config"
50
50
  ]);
51
- const trackerRef = useRef(null);
51
+ const [tracker, setTracker] = useState(null);
52
52
  useEffect(() => {
53
53
  if (!options.apiKey) {
54
54
  console.error(
@@ -56,26 +56,24 @@ function EasyFunnelProvider(_a) {
56
56
  );
57
57
  return;
58
58
  }
59
- if (!trackerRef.current) {
60
- trackerRef.current = EasyFunnel.init(__spreadProps(__spreadValues({}, options), {
61
- autoPageView: true,
62
- rules: config == null ? void 0 : config.rules
63
- }));
64
- }
59
+ const instance = EasyFunnel.init(__spreadProps(__spreadValues({}, options), {
60
+ autoPageView: true,
61
+ rules: config == null ? void 0 : config.rules
62
+ }));
63
+ setTracker(instance);
65
64
  return () => {
66
- var _a2;
67
- (_a2 = trackerRef.current) == null ? void 0 : _a2.destroy();
68
- trackerRef.current = null;
65
+ instance.destroy();
66
+ setTracker(null);
69
67
  };
70
68
  }, [options.apiKey]);
71
- return /* @__PURE__ */ jsx(EasyFunnelContext.Provider, { value: trackerRef.current, children });
69
+ return /* @__PURE__ */ jsx(EasyFunnelContext.Provider, { value: tracker, children });
72
70
  }
73
71
  function useEasyFunnel() {
74
72
  return useContext(EasyFunnelContext);
75
73
  }
76
74
 
77
75
  // src/hooks.ts
78
- import { useCallback, useEffect as useEffect2, useRef as useRef2 } from "react";
76
+ import { useCallback, useEffect as useEffect2, useRef } from "react";
79
77
  function useTrack() {
80
78
  const tracker = useEasyFunnel();
81
79
  return useCallback(
@@ -109,7 +107,7 @@ function useIdentify() {
109
107
  );
110
108
  }
111
109
  function useSectionRef(sectionName) {
112
- const ref = useRef2(null);
110
+ const ref = useRef(null);
113
111
  useEffect2(() => {
114
112
  const el = ref.current;
115
113
  if (el) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyfunnel/react",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "React/Next.js provider for easyfunnel.co analytics",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",