Category: Next.js, React and TypeScript

React: A component is changing an uncontrolled input to be controlled

Read this guide in Polish

After downloading the data, the form logs a warning about changing uncontrolled input to controlled. In the first render value can be undefined, and after loading it becomes a string, which changes the way the field is managed.

How to determine the source of the error

Check the initial state of useState and the values transferred to value and checked.

Compare the render before the API response with the render after it is completed.

What to do step by step

1. The upload is a stable input value, e.g. an empty string for the text field, and use value={value ???? Where appropriate.

2 . For checkbox control boolean, and for uncontrollable form use conscious defaultValue instead of mixing approaches.

How to check the score

The warning disappears after the first render and the entered data does not reset after the status update.

What to do

Do not patch the problem of assigning random text undefined to input.