vendredi 24 mars 2017

Error when using if, when updating the state in react

I wanted to update this variable when the condition is true, but it doesn't let me, thanks

 constructor(props){
        super(props);
        var isActive = false;

        this.props.items.map(item => (
                if(item.name == this.props.product.name) {
                    isActive = true;
                }
        ));

        this.state = {
            active: isActive
        };

        console.log(isActive);
        this.handleClick = this.handleClick.bind(this);

    }

Aucun commentaire:

Enregistrer un commentaire