javascript - ReactJs error - Warning: setState(...): Can only update a mounted or mounting component -
i getting error can please tell me how can debug further?
warning: setstate(...): can update mounted or mounting component. means called setstate() on unmounted component. no-op.
can help?
this component causing error:
var postal = require('postal'), contactchannel = postal.channel("contact"), react = require('react'); var contactselector = react.createclass({ getinitialstate: function() { return { selectedcontacts:[] }; }, handlechange: function(e) { var id = e.target.attributes['data-ref'].value; if (e.target.checked === true){ contactchannel.publish({ channel: "contact", topic: "selectedcontact", data: { id: id }}); } else{ contactchannel.publish({ channel: "contact", topic: "deselectedcontact", data: { id: id } }); } }, render: function() { var id = this.props.data.id; var isselected = this.props.data.isselected; return ( <div classname="contact-selector"> <input type="checkbox" checked={isselected} data-ref={id} onchange={this.handlechange} /> </div> ); } }); module.exports = contactselector;
the contactchannel channel i've setup using postal.js, https://github.com/postaljs/postal.js
contactchannel.subscribe("selectedcontact",function (data, envelope) { page.setpersonisselectedstate(data.id, true); basketchannel.publish({ channel: "basket", topic: "addpersontobasket", data: { personid: data.id } }); });
i suscribe publish in componentdidmount on parent page:
componentdidmount: function() { var page = this; this.loadcontacts(); page.subscribeevents(); },
listeners:
subscribeevents: function() {
var page = this; page.subscribetochannel(filterchannel, "searchfilterchange", this.listenerforsearchfilterchanged); contactchannel.subscribe("pagesizechanged", this.listenerforsizechanged); page.subscribetochannel(filterchannel, "genderfilterchange", this.listnerforgenderfilterchange); page.subscribetochannel(filterchannel, "rollmodefilterchange", this.listnerforrollmodefilterchange); page.subscribetochannel(filterchannel, "attendancemodefilterchange", this.listnerforattendancemodefilterchange) page.subscribetochannel(filterchannel, "messagetofilterchange", this.listnerformessagetofilterchange); contactchannel.subscribe("selectall", function (data) { page.loadcontacts(); }); contactchannel.subscribe("selectedcontact",function (data, envelope) { page.setpersonisselectedstate(data.id, true); basketchannel.publish({ channel: "basket", topic: "addpersontobasket", data: { personid: data.id } }); }); contactchannel.subscribe("selectall", function (data, envelope) { basketchannel.publish({ channel: "basket", topic: "selectall", data: { selectall: data.selectall } }); }); contactchannel.subscribe("refreshcontacts", function (data, envelope) { page.loadcontacts(); }); },
you're going using react incorrectly. react built componentized, you'll want doing in components.
when you're setting app, you'll want use postal's subscribe inside of each of components' getinitialstate
. then, unsubscribe postal channels in componentwillunmount
functions.
it seems offending code missing snippets in question, if post code on @ , tell still "subscribed" postal event on component no longer mounted.
Comments
Post a Comment