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

fix: make react hooks useable in component story #379

Merged
merged 1 commit into from
Oct 4, 2022

Conversation

zhouzh1
Copy link
Contributor

@zhouzh1 zhouzh1 commented Oct 3, 2022

Issue: N/A

What I did

When I added the useEffect and other react hooks in component stories, I encountered the React has detected a change in the order of Hooks error, after a investigation, found that the story preview content is got by the method of calling the story function, maybe we need to change it to render the story component. :)

image

How to test

Please explain how to test your changes and consider the following questions

  • Does this need a new example in examples/native? NO
  • Does this need an update to the documentation? NO

If your answer is yes to any of these, please make sure to include it in your PR.

@zhouzh1 zhouzh1 requested a review from dannyhw as a code owner October 3, 2022 03:26
@dannyhw
Copy link
Member

dannyhw commented Oct 3, 2022

@zhouzh1 hey sorry I missed this, seems good to me 👍. I'll just give it a run to make sure but I don't see why it wouldn't work.

@dannyhw dannyhw merged commit 485aba2 into storybookjs:next-6.0 Oct 4, 2022
@zhouzh1
Copy link
Contributor Author

zhouzh1 commented Oct 5, 2022

Hi, @dannyhw, I think it is due to the rendering mechanism inside React, even though a React component is essentially just a function, we still need to let React know that the function is a component, otherwise it will be treated as just a function, or just a part of the hosted component, then the hooks used in the function cause this kind of issue. :)

@dannyhw
Copy link
Member

dannyhw commented Oct 5, 2022

@zhouzh1 thanks for the extra info, that's good to know. Although I was referring to your fix seeming like it was fine and I wouldn't find any issue :)

anyway this is live now in the 6.0.1-beta.8 release

@zhouzh1 zhouzh1 deleted the fix/use_hooks_in_story branch November 8, 2022 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants