javascript - modifiy multiple react components on trigger -
i have input forms use on several places on single-page website. there single react-component class named subscribe
contains whole <form>
allowing user enter email , subscribe newsletter.
when user submits subscribes in <subscribe>
, want change content of every occurence of <subscribe>
on page. easy single <subscribe>
user used, can not find suitable way modifiy state of other <subscribe>
components. i'm, using plain javascript modifiy dom-nodes.
is there way directly in react?
yeah, better done flux comment said in post. should store changes , manipulate storage data service.
you can check https://facebook.github.io/flux/ further information.
but, if you're rendering page react can set state page , pass 1 prop in each <subscribe>
component. should manipulate submission in same page or through mixin not let component job state changed well.
in page:
getinitialstate: function () { return { alreadysubscribed: false }; }
when user hit subscribe button: this.setstate({alreadysubscribed: true});
when render each <subscribe>
component pass prop, example: disablesubscribe={this.state.alreadysubscribe}
Comments
Post a Comment