Open undeletable opened 5 months ago
I think the "modern" way to do is to conditionally assign the event handler directly within the onClick
, like for example:
<button
onClick={isCountButtonActive ? () => setCount(currentCount => currentCount + 1) : undefined}
>
Increment count
</button>
@saul-atomrigs Thanks. I know several ways to work that around, including your approach. But the code in my example should work too, as it's valid and spread operator usage too, and not less 'modern' one for sure. That's why I've raised the issue.
I'm going to work on the fix
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
Still an issue. Upgraded to the latest RC in repository with reproduce.
There's PR with fix: https://github.com/facebook/react/pull/29925 Updated it with the latest changes from main branch
Summary
Prerequisites
Result
Error is thrown when conditional is evaluated to
false
:Code fragment where it's thrown:
Reproduction
https://github.com/undeletable/jsx-spread-with-react-19-rc Click 'Toggle count button state' to reproduce