Reputation: 222865
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
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