snippetreactMajor
How to set default Checked in checkbox ReactJS?
Viewed 0 times
checkedsetreactjscheckboxhowdefault
Problem
I'm having trouble to update the checkbox state after it's assigned with default value
After assigning
checked="checked" in React.var rCheck = React.createElement('input',
{
type: 'checkbox',
checked: 'checked',
value: true
}, 'Check here');After assigning
checked="checked", I cannot interact the checkbox state by clicking to uncheck/check.Solution
If the checkbox is created only with
Credit to @nash_ag
React.createElement then the property defaultChecked is used.React.createElement('input',{type: 'checkbox', defaultChecked: false});Credit to @nash_ag
Code Snippets
React.createElement('input',{type: 'checkbox', defaultChecked: false});Context
Stack Overflow Q#32174317, score: 64
Revisions (0)
No revisions yet.