Docs: Improve error message and docs for mixing Storybook and React hooks in render functions#33935
Conversation
…ook and React hooks Co-authored-by: valentinpalkovic <5889929+valentinpalkovic@users.noreply.github.com>
|
View your CI Pipeline Execution ↗ for commit 2dd18d2
☁️ Nx Cloud last updated this comment at |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughEnhanced an internal hook error message and updated docs to warn against mixing Storybook preview hooks with framework hooks, recommending Storybook's preview-api hook equivalents; no public API or runtime control-flow changes. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Comment |
Package BenchmarksCommit: No significant changes detected, all good. 👏 |
jonniebigodes
left a comment
There was a problem hiding this comment.
This is looking great. I just tweaked the messaging a bit and will get it in once the checklist clears.
Using Storybook hooks (e.g.
useArgs) alongside React hooks (useState,useEffect,useRef) in the same render function causes a cryptic error on re-render — React re-renders don't run through Storybook's hook context, so Storybook hooks fail.Changes
Better error message (
preview-api/modules/addons/hooks.ts): Extended the existing error to explain the root cause and point directly to the fix — use Storybook's equivalents fromstorybook/preview-apiinstead of React's hooks.Warning callout in
args.mdx: Added after theuseArgscode example explaining the constraint, listing the available Storybook hook equivalents, and showing correct usage:Updated
decorators.mdx: Improved thehookscontext property description to mention the re-render constraint and point tostorybook/preview-apiequivalents.Original prompt
Storybook preview hooks can only be called inside decorators and story functions.#33804✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Summary by CodeRabbit
Documentation
useArgsanduseGlobalsare available in stories and decorators.Improvements