Skip to content

Commit

Permalink
Use AsyncStorage to remember if Storybook was open
Browse files Browse the repository at this point in the history
  • Loading branch information
phelipetls committed Feb 26, 2022
1 parent 23a9546 commit 456b50e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,25 @@ import {
LogBox,
DevSettings,
} from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';

LogBox.ignoreLogs(['Require cycle:']);

const App = () => {
const [showStorybook, setShowStorybook] = useState(false);

useEffect(() => {
const getStoredShowStorybook = async () => {
setShowStorybook((await AsyncStorage.getItem('@storybook')) === 'true');
};

getStoredShowStorybook();
}, []);

useEffect(() => {
AsyncStorage.setItem('@storybook', String(showStorybook));
}, [showStorybook]);

useEffect(() => {
DevSettings.addMenuItem('Toggle Storybook', () => {
setShowStorybook(v => !v);
Expand Down

0 comments on commit 456b50e

Please sign in to comment.