I have a component I would like to uncheck from a postal.js subscription. Using my code below the checkbox is always checked.
I am storing the value in state and setting it in ComponentDidMount. Can anyone tell me how I can uncheck it once I receive the subscription:
var postal = require('postal');
var contactChannel = postal.channel("contact");
var SelectAll = React.createClass({
getInitialState: function() {
return {
selected:false
};
},
handler: function(e) {
var updatedContacts = [],
contacts = this.props.data.contacts,
topic = 'selectAll',
checked = false,
channel = 'contact';
if (e.target.checked === true){
checked = true;
}
contactChannel.publish({
channel: channel,
topic: topic,
data: {
selectAll: checked
}});
},
render: function() {
var isSelected = this.state.selected;
return (
<div className="contact-selector">
<input type="checkbox" checked={isSelected}
onChange={this.handler} ref="checkAll" />
</div>
);
},
setChecked: function(){
this.setState({ selected: true });
},
componentDidMount: function() {
contactChannel.subscribe("deselectedContact", function (data) {
this.setChecked();
});
}
});
module.exports = SelectAll;
Aucun commentaire:
Enregistrer un commentaire