0

How to get check value in react when passing dynamic value in checkbook and get these value when checkbook is checked

  • Possible duplicate of [Get the value of checkbox using ref in React](https://stackoverflow.com/questions/36833192/get-the-value-of-checkbox-using-ref-in-react) – GalAbra Jun 19 '19 at 20:03

1 Answers1

0

Hey from what I understand, you are asking about how to check the value of your checkbox ( true if it is checked, false otherwise).

You can have your checkbox value stored in your component state so that you can access it anywhere in your component, then call setState() whenever the onChange event is fired.

class Profile extends Component {
    constructor(props) {
        super(props);

        this.state = {
           checked: true
        };

    render() {
        return (
            <input
            type="checkbox"
            checked={this.state.checked}
            onChange={checked => { this.setState({ checked }) }} />
        )
    }
}
JKleinne
  • 1,270
  • 7
  • 14