A simple React hook for toggling something on and off with a bookmark link. If the feature is only meant for internal testing etc, this hook makes it "safe" to release a feature into production without letting end users see it. (Of course, nerdy developers with development tools will be able to find it.)
You can use a simple javascript:url as a bookmarklet that triggers a custom event. The name of the
event shoud be identical with the featureName
in the code below:
Drag this link to the bookmarks bar to toggle Fancy Feature in our product:
<a href="javascript:window.dispatchEvent(new Event('fancy_feature'));">Toggle Fancy Feature</a>
More generally this hook could be used as a pub/sub architecture, where independent widgets (React and others) communicate with each other via sending and listening for custom events on window. Then of course, you could send more complex data structures via the event object, and set that data object instead of flipping a simple boolean.