React is messing with me.
I have a checkbox which gets its “checked”-state from my component state:
Copy code
checked = state.active == true
I do have a custom
onChange
handler, which sets the state:
Copy code
val target = event.target as HTMLInputElement
setState {
active = target.checked
}
When checking the checkbox, react throws this message:
Copy code
react_devtools_backend.js:6 Warning: A component is changing an uncontrolled input of type checkbox to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: <https://fb.me/react-controlled-components>
✅ 1
t
turansky
05/31/2020, 2:55 PM
Will it work with precalculated value?
Copy code
val target = event.target as HTMLInputElement
val newActive = target.checked
setState {
active = newActive
}
b
Björn Mayer
05/31/2020, 3:04 PM
same result.
I tried to set
active
to true, when initialising:
Copy code
override fun State.init(props: Props) {
active = true
}
And then the message appears, without me doing any click. Refreshing the page is enough