Skip to content

Instantly share code, notes, and snippets.

@chestozo
Created April 15, 2020 15:07
Show Gist options
  • Save chestozo/2f40a8d0bf64a9c6d23d4e74ae3aa3f9 to your computer and use it in GitHub Desktop.
Save chestozo/2f40a8d0bf64a9c6d23d4e74ae3aa3f9 to your computer and use it in GitHub Desktop.
Router params access from storybook story
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>
)
}
@chestozo
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment