question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable hook conditionally

See original GitHub issue

I 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:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
elgorditosalserocommented, Sep 28, 2021

Thanks for the suggestion! Any ideas how this could be solved technically without the need to set up separate GTM envs?

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.

0reactions
elgorditosalserocommented, Dec 27, 2021

Hi @olarcher ,

could you try 2.2.0? #42 should help you

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found