Created
October 18, 2023 12:32
-
-
Save MarceloPrado/e670e2dc0b94eaf62c10d1bc54369bc9 to your computer and use it in GitHub Desktop.
Dynamically toggle between storybook and app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { config } from "@/app/config"; | |
import { createLogger } from "@/app/observability"; | |
import { useEffect } from "react"; | |
const { appEnv } = config; | |
const logger = createLogger("developer/storybook"); | |
export const useToggleStorybook = () => { | |
const [isStorybookEnabled, setIsStorybookEnabled] = useState(false) | |
useEffect(() => { | |
if (appEnv === "dev") { | |
// eslint-disable-next-line @typescript-eslint/no-var-requires | |
const { registerDevMenuItems } = require("expo-dev-menu"); | |
logger.info("Registering dev menu items"); | |
const devMenuItems = [ | |
{ | |
name: "Toggle storybook", | |
callback: () => { | |
logger.info("Toggling storybook"); | |
setIsStorybookEnabled(prev => !prev) | |
}, | |
}, | |
]; | |
registerDevMenuItems(devMenuItems); | |
} | |
}, [toggle]); | |
return appEnv === "dev" | |
? { isStorybookEnabled } | |
: { isStorybookEnabled: false }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nevermind the
toggle
value in the deps array - it's a copy/paste leftover. See original post here: https://twitter.com/marceloterreiro/status/1714620600516272360