Skip to content

Instantly share code, notes, and snippets.

@javierguzman
Created September 28, 2021 20:08
Show Gist options
  • Save javierguzman/a5af04829f5ca00cae74041d22e5a39b to your computer and use it in GitHub Desktop.
Save javierguzman/a5af04829f5ca00cae74041d22e5a39b to your computer and use it in GitHub Desktop.
Storybook with react-router
export const withMemoryRouter = (StoryComponent, { parameters: currentURL }) => {
if (!currentURL) {
return <StoryComponent />;
}
const { path, route } = currentURL;
console.log('Current url available');
console.log(path, route);
return (
<MemoryRouter initialEntries={[encodeURI(route)]}>
<Route path={path}>
<StoryComponent />
</Route>
</MemoryRouter>
);
};
export default {
component: Footer,
title: 'Common/Footer',
parameters: {
notes: { notes }
}
}
const Template = (args) => <Footer {...args} />;
export const defaultFooter = Template.bind({});
export const landingPageFooter = Template.bind({});
landingPageFooter.parameters = {
currentURL: {
route: '/',
path: '/'
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment