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

Change event members are read-only

Detect​

  • In your onChange or onSubmit handlers: an assignment to a member of the event, such as event.formData = normalize(event.formData).
  • In the type checker: TS2540: Cannot assign to 'formData' because it is a read-only property.

Change​

IChangeEvent is now declared on its own instead of as a Pick of the Form's internal state, and every member is readonly. Readonly modifiers don't affect assignability, so a handler that reads the event or passes it on compiles as before. Only code that assigns into the event breaks:

-onChange={(event) => { event.formData = normalize(event.formData); setData(event.formData); }}
+onChange={(event) => setData(normalize(event.formData))}

The modifier is shallow. It stops event.formData = ... and leaves a write inside formData compiling, so treat the whole event as immutable. Received form data must not be mutated at any depth; see Form data is deep-frozen in development.

Verify​

  • Your handlers compile and copy data out of the event before changing it.
  • Nothing writes inside event.formData or any other member of the event.

Also read: