Disable hook conditionally
See original GitHub issueI would like to use this library in a larger project. On certain (dev) environments data should not be sent to GTM. Is it possible to disable GTM integration completely, e.g. by checking the value of an environment variable (if GTM_CONTAINER_ID is set then activate, else don’t)? To my understanding, since useGTMDispatch
is a hook it cannot be called conditionally. Is there any way to deactivate the dispatch anyway?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
reactjs - How to conditional disable input depend on another ...
I want to conditional disable input based on another input value. ... How could I achieve it with react-hook-form? I want to disable, ......
Read more >Conditional React Hooks | Ben Ilegbodu
React Hook "useClickAway" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you ...
Read more >You Can't Call Hooks Inside Conditions? Yes you can
Calling hooks conditionally breaks the rules, yes. Wrap the hook with a component and render that component optionally to toggle the usage of ......
Read more >Rules of Hooks - React
This is why Hooks must be called on the top level of our components. If we want to run an effect conditionally, we...
Read more >Fix - React Hook "useEffect" is called conditionally
The fix is simple. Just move the useEffect block before the if condition and the code should work fine. import React, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the only way you have at the moment, is wrapping into ifs the dispatcher based on your environments.
But I can think to add a variable to enable/disable dispatching in the future.
Hi @olarcher ,
could you try 2.2.0? #42 should help you