Toggle toolbar with a flag
Learn how you can control who gets the toolbar in production by toggling a feature flag on/off
In some cases, you want to limit who has access to the toolbar in production. If you already have an "admin" or "internalUser" boolean on the user model, that is how most people decide whether to show the toolbar.
Beyond those simple cases, using a feature flag that you can enable for certain people is a great way to manage who gets to see the toolbar.
Here's an example of how it can be done with the React SDK:
Create the flag:
$ npx reflag new toolbarIf you've set the
toolbarprop on the<ReflagProvider>, remove it. We'll manage this by callingclient.showToolbar()when the flag is enabled.Put this tiny component inside the
<ReflagProvider>:
function ToolbarFlagControl() {
const client = useClient();
const {isEnabled: toolbarEnabled} = useFlag("toolbar");
useEffect(() => {
if (toolbarEnabled) {
client?.showToolbarToggle();
}
}, [toolbarEnabled]);
}Done! You can now enable/disable the toolbar for users by toggling the toolbar feature flag for them inside Reflag.
Last updated
Was this helpful?