Open jchavarri opened 10 months ago
This makes sense, because why would key be added if no needed
Sometimes it's useful to have key
specified outside of an array to re-mount the element. Ref to React docs: https://react.dev/reference/react/useState#resetting-state-with-a-key
Alternative take to having typed keys based on the ideas from #812.
Centers the typing around the
React.array
function. The only case where keys should be added is when children are variable size arrays, and not literals. SoReact.array
might be the best spot to place the restriction.The issue is that
React.array
is used in the ppx to convert literals of children like<div> foo bar </div>
. To cover that case, a new functionReact.unsafeArray
is added.The type errors look like:
One downside is that usages of
key
outside arrays now would trigger a type error. This makes sense, because why wouldkey
be added if no needed, but who knows what could break. Also, in all cases the error happens far away from where the component is defined.E.g. for this code:
the error is: