To use global or local state in the application React?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
7 views
Prompt, please, where you can read about best practice for state management in React app?

The idea of redux or freezerjs with one global state is great,
but every sneeze a separate reducer or the handler event with the subsequent rendering of the whole application somehow doesn't look good.
It is clear that bypass the whole tree will occur quickly, and most of the component will not perform render on condition of shouldComponentUpdate, but isn't that a beautiful solution?

I wrote a few dozen simple component, each of which performs its function, and now there is a problem to merge them into one app.

Used this approach:

Component gets props from the parent and generate the html code.
At different event from the user, the component changes its state and makes your render.
In order to let the parent know that have changed state and might need new props, I use a callback which convey the current state of the component and the name of the event which caused it

const componentWillUpdate = () => { let { onChange } = props if (typeof onChange === 'func') => { onChange({ state: this.state, event: " }) } }


the parent write the handler for this event

 this.handleComponentChange(opts) }>

With this approach, you can write components without thinking about some global things, but it turns out that I need to transfer data from the leaves up the tree, each parent to write their event handlers, and then back down to pass the props. Looks like not too much.

Where to find balance?
by | 7 views

1 Answer

0 like 0 dislike
How about MobX?
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Apr 24, 2019 by TchernyavskD
0 like 0 dislike
5 answers
110,608 questions
257,186 answers
0 comments
35,593 users