1

I want to uncheck the checkbox, when props changes.

How can I do this ?

This is my code:

<input type="checkbox" value={inventory.id}
    defaultChecked={_.some(this.props.cart.data, (cart) => {
                       return cart.id === inventory.id
                   })}
    onClick={(e) => this.addToCart(e, inventory)}/>

When I remove data from this.props.cart, checkbox should be unchecked.

Thank you

1 Answer 1

2

Try toggling the checked property not the defaultChecked property

render: function() {
    return <input type="checkbox" 
                  checked={_.some(this.props.cart.data, (cart) => cart.id === inventory.id)} 
                  onClick={(e) => this.addToCart(e, inventory)}/>
}

See the react docs for more examples:
https://facebook.github.io/react/docs/forms.html#handling-multiple-inputs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.