0

I'm calling function changeState on clicking ListItem but this is not working. Some solution suggested to solve this using bind() but I didn't understand about that so please explain about bind().

class TodoList extends Component {

    constructor(props) {
        super(props);
        this.changeState = this.changeState.bind(this);
    }
    changeState() {
        console.log('change');
        //this.props.toggleToDo(param);
    }

    render() {
        const todolist = this.props.todos;
        return (
            <div>
                <ul>
                {
                    todolist.map(function(listValue) {
                        return <ListItem key={listValue.id} text={listValue.text} onClick={this.changeState} />
                    })
                }
                </ul>
            </div>
        );
    }
}
devd_102
  • 13
  • 4

0 Answers0