-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading external data before adding story #696
Comments
Could suggest something like class LoadData = extends React.Component {
state = {
data: null
}
componentDidMount() {
axios.get(this.props.url).then(data => this.setState({ data }))
}
render() {
return this.props.children(this.state.data)
}
}
storiesOf('DataViewer')
.add('test', () => (
<LoadData url="http://api.someURLtogetdata.com">
{data =>
<TestStory data={data} />
}
</LoadData>
)) |
Thank you for the tip @einarlove! This issue hints at the same problem and has a possible solution: #713 What do you feel about it? I imagine the API would look like this (this is not implemented): storiesOf('DataViewer')
.add('test', () => axios
.get('http://api.someURLtogetdata.com')
.then(({ data }) => <TestStory data={data} />)
) |
I would like to hear your feedback! If you think the solution I just posted would be fine for your usecase, let's talk about it in this issue: #713. If you disagree and want another API, you're welcome to re-open this issue! |
Is it possible to do some async work like fetching of data via external API before rendering/adding a story?
Kinda like this inside:
This doesn't work. I also tried doing something like this:
Any tips on how to achieve something like this with storybook?
The text was updated successfully, but these errors were encountered: