dimanche 8 août 2021

Getting TypeError: this is undefined on checkbox

So, I am trying to create a checkbox component but I am having an issue. My CheckedBox.js is this:

import React, {useState} from 'react';

function CheckedBox() {

return(
    <label>
      <input type="checkbox"
        defaultChecked={this.state.checked}
        onChange={this.handleChange.bind(this)}
      />
      </label>
)

}

export default CheckedBox;

And this is the part I am calling CheckedBox:

<CheckedBox checked={checked} handleChange={() => setChecked(!checked)}/> MyCheckBox

I am getting the error TypeError: this is undefined. How can I fix this?




Aucun commentaire:

Enregistrer un commentaire