mufa

Share state in top level React components

风流意气都作罢 提交于 2020-01-02 07:36:51
问题 I need to use react in different parts of my page but share the same state so I made this on the top level: ReactDOM.render( <App />, document.getElementById('root') ); ReactDOM.render( <Dragbar />, document.getElementById('offCanvas') ); The main code is "App" but how do I send state to "Dragbar"? (I only need to send it not set). Is this where I need to start learning redux etc? I've just started learning React so haven't looked at other libraries yet. P 回答1: working with redux can help you

Stop the communication between react components using mufa after a condition

笑着哭i 提交于 2019-12-20 02:11:07
问题 I am using the sub/pub pattern via mufa to make communication between React components instead of props. Then, we will mitigate the logic in the Parent component (as you will notice that in the following snippet). const {on, fire} = mufa; class Input extends React.Component { onChange(event) { fire('input_change', event.target.value); } render() { return <input onChange={this.onChange.bind(this)} /> } } class Label extends React.Component { state= {text: ""}; componentDidMount() { on('input

Share state in top level React components

十年热恋 提交于 2019-12-06 04:46:09
I need to use react in different parts of my page but share the same state so I made this on the top level: ReactDOM.render( <App />, document.getElementById('root') ); ReactDOM.render( <Dragbar />, document.getElementById('offCanvas') ); The main code is "App" but how do I send state to "Dragbar"? (I only need to send it not set). Is this where I need to start learning redux etc? I've just started learning React so haven't looked at other libraries yet. P doronn working with redux can help you share one state all over your app without thinking what data to pass and what not. if you want to

Stop the communication between react components using mufa after a condition

巧了我就是萌 提交于 2019-12-01 21:21:48
I am using the sub/pub pattern via mufa to make communication between React components instead of props. Then, we will mitigate the logic in the Parent component (as you will notice that in the following snippet). const {on, fire} = mufa; class Input extends React.Component { onChange(event) { fire('input_change', event.target.value); } render() { return <input onChange={this.onChange.bind(this)} /> } } class Label extends React.Component { state= {text: ""}; componentDidMount() { on('input_change', this.onInputChange.bind(this)); } onInputChange(inputValue) { this.setState({text: inputValue})