#array dependancy on useEffectHook
9 messages · Page 1 of 1 (latest)
if you don't include dependency array, every time the component re-renders will execute your callback.
You would probably only want to do it on the first page load. An empty dependency list would do that for you.
hey Bence , thankyou for your reply. Will including a dependancy array stop ReactGA from collecting user's interactivity with the site? eg button clicks since this code only runs once when the site first loads?
It will run once the application has been loaded. If you refresh the page this callback will get executed.
The problem with not having a dependency list provided is that every action which somehow end up with this component's re-render will trigger the callback.
I believe adding the empty dependency list should solve your issue.
yes i also do believe that adding an empty array will solve the issue. However what I'm worried about is that the code will only run once when the page first loads and analytics wont be able to capture user's events and the pages the users navigate . So instead of including an empty array dependancy , is there an alternative dependancy i can include in the array for the code to run only when the user interacts/ does certain action in the site?
ooh i found a solution in stackoverflow. https://stackoverflow.com/questions/52724447/how-to-use-google-analytics-with-react
Thankyou Bence , appreciate your output. : )