Created
April 15, 2020 15:07
-
-
Save chestozo/2f40a8d0bf64a9c6d23d4e74ae3aa3f9 to your computer and use it in GitHub Desktop.
Router params access from storybook story
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 React from 'react' | |
import { MemoryRouter, Route } from 'react-router' | |
export default { | |
title: 'UserCard', | |
decorators: [], | |
} | |
const UserCard = ({ | |
match: { | |
params: { id }, | |
}, | |
firstName, | |
lastName, | |
}) => <div>{`${firstName} ${lastName} ${id}`}</div> | |
export const Default = () => { | |
const props = { | |
firstName: 'Al', | |
lastName: 'Pacino', | |
} | |
return ( | |
<MemoryRouter initialEntries={['/user/108']}> | |
<Route | |
component={(routerProps) => <UserCard {...routerProps} {...props} />} | |
path='/user/:id' | |
/> | |
</MemoryRouter> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you. I was worried about the dependence of useParams hooks, and it helped me a lot.