State let component remember information and we need it when a certain user action needs to change data from one value to other value.
When Designing state in React Apps I follow a couple of guidelines that might be helpful for you:
1) ๐๐ฎ๐ญ๐ฅ๐ข๐ง๐ ๐๐ฌ๐๐ซ๐ฌ ๐๐๐ก๐๐ฏ๐ข๐จ๐ซ๐ฌ ๐๐ง๐ ๐๐จ๐ง๐ฌ๐๐ช๐ฎ๐๐ง๐๐๐ฌ
The first step is to write all the steps users will do and what are the results they will see by using that component. This will force us to think about deeply what our componentโs purpose actually is.
So we observed what are the commands that can be given by users as they interact with that component on the screen and what are the responses they got.
2) ๐๐ฆ๐ฆ๐๐ซ๐ฌ๐ ๐ฒ๐จ๐ฎ๐ซ๐ฌ๐๐ฅ๐ ๐ข๐ง ๐จ๐ง๐ฅ๐ฒ ๐๐ก๐๐ง๐ ๐๐ฌ
We need to set a specific intention here and donโt let ourselves be distracted by what is static in that component.
Our only awareness here should be what is changing on the screen and remove static parts from our mind. This leads us to narrow down our focus to one thing only and simplify things.
Alright, that's for state design. Time for think of a few strategies of where to place a state: Ask Yourself,
โ which other components need that state? If the answer is 0, then place that state only in that component and we are done.
โ Does that state needed by many different components such as - children, sibling, parent - then itโs a global state.
๐ป๐๐๐๐ ๐๐๐ ๐๐๐ ๐๐๐๐ ๐๐๐ ๐. ๐ฐ ๐๐๐๐ ๐๐๐ ๐๐๐๐ ๐๐๐ ๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐ ๐๐๐๐๐ ๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐.
Top comments (0)