Spreading a possibly undefined value?

Unhandled Runtime Error

TypeError: items is undefined
Source

components/Inputs/Checkbox/Checkbox.js (16:36) @ updateCheckedState

  14 | if (e.target.checked) {
  15 |   const nameOrLabel = label ?? name;
> 16 |   setCurrentlyChecked([...Array.from(currentlyChecked), { // normally an object array
     |                                ^
  17 |     label: nameOrLabel,
  18 |     value
  19 |   }]);

I guess this solution to coerce undefined to an empty array is not working. Anyone know a fix?

Well, currentlyChecked always has to be an an array or array-like thing, maybe you need to set it as an empty array if it’s undefined – you can’t use from on something that can’t be converted to an array (like undefined)

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.