Skip to content
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

Convert Styleguidist's initialState/setState to React's useState hook in docs #325

Open
vine77 opened this issue Oct 7, 2020 · 6 comments

Comments

@vine77
Copy link
Contributor

vine77 commented Oct 7, 2020

Remove usage of Styleguidist's initialState/setState/state and replace with React’s useState hook instead. (This will be required when we upgrade to Styleguidist 11.) For example:

- initialState = { count: 42 };
- <Button onClick={() => setState({ count: state.count + 1 })}>{state.count}</Button>
+ const [count, setCount] = React.useState(42);
+ <Button onClick={() => setCount(count + 1)}>{count}</Button>
@trybick
Copy link

trybick commented Oct 7, 2020

Hi @vine77 I can do this - are these docs in the readme?

@vine77
Copy link
Contributor Author

vine77 commented Oct 7, 2020

Thanks @trybick! This would be the docs for each component that use Styleguidist's initialState/setState. We have *.md Markdown files in the same folder as each component that include fenced code blocks, which get rendered into live editable examples in the docs. This search of *.md component docs files that have setState should show all the current instances that can be refactored to use React's useState hook instead.

@trybick
Copy link

trybick commented Oct 7, 2020

Sounds good, ty for the info, will do.

@trybick
Copy link

trybick commented Oct 10, 2020

@vine77 I've started a PR for this - #334 - but when I run the site, I'm getting not defined errors. For example in Input.md I'm getting value is not defined. I guess I can add useState to create value. But I'm confused how state was working before without initialState in Input.md?

@trybick
Copy link

trybick commented Oct 10, 2020

I think it might be better if this was broken into multiple Issues, one for each component because the PR #334 is pretty big and there are syntax issues with it. It's tedious to fix them because there's no IDE syntax support in the MD files (at least that I've seen).

I'm going to stop working on this, but the branch is started for someone else to complete if they want. What's remaining is the fix the syntax issues by running the app and addressing the errors in the console.

@vine77
Copy link
Contributor Author

vine77 commented Oct 12, 2020

Thanks @trybick! I left a comment on #334.

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

Successfully merging a pull request may close this issue.

2 participants