inrupt / solid-lib-comparison

Three branches with common Solid operations implemented in rdflib, ldflex and Tripledoc, respectively
6 stars 2 forks source link

Ensure inputs are always controlled #3

Closed RubenVerborgh closed 4 years ago

RubenVerborgh commented 4 years ago

When a service would return undefined for name or nick (as is allowed by the type), and the value would be updated by the user, the respective field would change from uncontrolled to controlled state, leading to

Warning: A component is changing an uncontrolled input of type text to be controlled.

The direct cause was that React.useState<string>() was called without supplying a default value of "". However, when changing that, the render logic (in particular the value property) would fail.

The root cause of this is that the same state was being maintained twice: name and nickname were additionally modeled via profileData.

This PR untangles that logic and fixes the React warning.

Vinnl commented 4 years ago

Since it was used in a code demo (see #6) I just assumed that these fields would be set, because they were. I've now removed that assumption in the master branch and rebased the specific example branches on top of that, so that should fix this.