Created
September 23, 2021 07:54
-
-
Save javierguzman/8374bcb7617f75d0d0d2454d6e1e0cab to your computer and use it in GitHub Desktop.
Storybook with Redux store
This file contains hidden or 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 React, { Suspense } from "react"; | |
import { LoaderSuspense } from "features/Loader"; | |
import { BrowserRouter } from 'react-router-dom'; | |
import { Provider } from 'react-redux'; | |
import store from '@Store'; | |
export const withSuspense = StoryComponent => { | |
return ( | |
<Suspense fallback={<LoaderSuspense />}> | |
<StoryComponent /> | |
</Suspense> | |
); | |
}; | |
export const withStore = StoryComponent => { | |
return ( | |
<Provider store={store}> | |
<StoryComponent /> | |
</Provider> | |
); | |
}; |
This file contains hidden or 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 React from 'react'; | |
import Header from '../Header'; | |
import notes from './readme.md'; | |
export default { | |
component: Header, | |
title: 'Common/Header', | |
parameters: { | |
notes: { notes } | |
} | |
}; | |
const Template = (args) => <Header {...args} />; | |
export const LoggedOutHeader = Template.bind({}); | |
LoggedOutHeader.args = { | |
store: { | |
auth: { | |
correctLogin: true, | |
user: {}, | |
errorMessage: '' | |
} | |
} | |
}; | |
export const LoggedInHeader = Template.bind({}); | |
LoggedInHeader.args = { | |
store: { | |
auth: { | |
correctLogin: true, | |
user: { | |
id: '12345', | |
roles: [], | |
sightVotes: [] | |
}, | |
errorMessage: '' | |
} | |
} | |
}; |
This file contains hidden or 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
const store = configureStore({ | |
reducer: reducers, | |
middleware: getDefaultMiddleware(), | |
devTools: process.env.NODE_ENV !== 'production', | |
enhancers: createEnhancers() | |
}); | |
export default store; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment