Skip to main content
Version: Current (v7.0.0-beta.3)

A transformChange that drops a cleared key loses the clear

Detect​

  • mergeDefaultsIntoFormData: 'useDefaultIfFormDataUndefined' in your defaultFormStateBehavior.
  • A transformChange in your code that removes keys holding undefined, for example by destructuring them away.
  • A transformChange that copies with JSON.parse(JSON.stringify(next)).
  • On the rendered page, a field the user cleared that fills its default back in.

Change​

A clear holds only while the key is there holding undefined. A missing key used to count as cleared too. Pass the undefined through to keep it:

-const transformChange = ({ code, ...rest }) => (code ? { ...rest, code: code.toUpperCase() } : rest);
+const transformChange = (next) => (next.code === undefined ? next : { ...next, code: next.code.toUpperCase() });

JSON.parse(JSON.stringify(next)) drops every undefined. Copy with structuredClone() instead:

-const copy = JSON.parse(JSON.stringify(next));
+const copy = structuredClone(next);

Verify​

Also read: