-
-
Notifications
You must be signed in to change notification settings - Fork 370
Open
Labels
hook: useRendertype: expected behaviorThe current behavior is already the one expected.The current behavior is already the one expected.
Description
Bug report
Current behavior
If component CountButton contains a React hook, then React will crash when isCounter changes:
{isCounter ? (
<Button render={CountButton} />
) : (
<Button>No counter</Button>
)}You can work around this by rendering the element before passing it in:
{isCounter ? (
<Button render={<CountButton />} />
) : (
<Button>No counter</Button>
)}Expected behavior
Neither example should crash React.
Reproducible example
https://stackblitz.com/edit/vitejs-vite-ykx9a7mz?file=src%2FApp.jsx
Base UI version
v1.1.0
Additional context
This is a pretty big footgun. It's apparently due to React optimistically merging the state of the same component at the same position in the tree.
These are the two errors we've seen in this scenario:
Minified React error #300
Rendered fewer hooks than expected. This may be caused by an accidental early return statement.
Minified React error #310
Rendered more hooks than during the previous render.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
hook: useRendertype: expected behaviorThe current behavior is already the one expected.The current behavior is already the one expected.