Ad

React CheckedLink How To Access Value On Change

- 1 answer

I am using React to write a simple component for a checkbox

<input type="checkbox" checkedLink={this.linkState('checkedValue')} />

I cannot however figure out what code gets triggered on change of the checkbox value. Am I supposed to retrieve the value onFocus or is there a better convention for retrieving the value after a change.

Ad

Answer

You could grab the state of your checkbox by adding an onChange handler something like this:

function handleChange (event) {
  console.log(event.target.checked)
}

<input onChange={handleChange} type='checkbox' />
Ad
source: stackoverflow.com
Ad