-
Notifications
You must be signed in to change notification settings - Fork 32
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
How to display classes with state #17
Comments
Hi, Can you provide an example of what your component look like and what you want as a result in the addon panel ? |
So here's an example. .addWithJSX('Controlled table (w/ external state)',
withNotes('Using React state to control the table ')(() => {
class TableContainer extends React.Component {
constructor() {
super()
this.state = {
rows: [],
loading: true,
}
}
fetchData = (query) => {
this.setState({ loading: true })
fetchServer(query).then((res) => {
this.setState({
rows: res.data,
pages: res.pages,
loading: false,
})
})
}
render() {
const { rows, columns, loading } = this.state
return (
<AwesomeTable
onChange={this.fetchData}
loading={loading}
data={rows}
columns={columns}
/>
)
}
}
return <TableContainer />
}),
) But all that comes up there is |
Hi, sorry for the delay, i was on vacation. |
It would be fine if I could just add a Perhaps that would be doable at some point? |
I tried that too but storybook doesn't accept the class as a return statement because it can't render it. The jsx you see in the panel is an interpretation of the rendered story and the story rendered won't contain the logic, only the react elements :/ storybook return me this error : |
Yea, shame. A future version of storybook will probably fix that. No worries, thanks for checking though. |
Something we can do on the storybook side? |
A way to help would be to accept a React class as a the return statement, but even then i'm not sure storybook-addon-jsx can handle this kind of code because we only able to reverse to JSX and js code source. A more general way would be to give access to the untranspiled code (source code) in the object send to the addon. |
hi, i know this is a bit old, but it's also the top result on quick google searches relating to this issue, so i thought i'd add a comment you can just define your class elsewhere in the file like you normally would. // your example
withNotes('Using React state to control the table ')(() => {
class TableContainer extends React.Component { you can instead have it defined outside of the 'storiesOf' chain altogether (but in the same file), and then render it like you normally would withNotes('Using React state to control the table ')(() => {
return <TableContainer />;
}) at least, in @batjko 's example, nothing is being "passed in" from above, so it's not strictly coupled to the storybook functions at all. |
I just encountered a similar issue: Some of our components are using a theme from context which requires us to use either a All we see in the addon is a simple |
We have a component that only makes sense if it is used as a class, because we need to demonstrate how it handles state.
I can't find a way of letting the JSX output of my story show the entire class. If I return the class in .addWithJsx, the component simply won't show up at all.
Any ideas?
The text was updated successfully, but these errors were encountered: