Estus Flask
Estus Flask

Reputation: 222865

<input> value prop is applied without re-rendering

In this example, value prop is applied on <input> change even though the component isn't re-rendered:

const App = () => <input value="foo"/>

This efficiently results in read-only input. This behaviour is specific to React.

Why exactly does it work this way? The explanation from official sources is welcome.

Can we make this <input> work as in plain HTML without introducing onChange?

Upvotes: 0

Views: 33

Answers (1)

Denis Kuratovich
Denis Kuratovich

Reputation: 287

Yes, you can, just change:

const App = () => <input defaultValue="foo"/>

for using 'Uncontrolled Component'

More information here: https://reactjs.org/docs/uncontrolled-components.html

Upvotes: 1

Related Questions