DEV Community

Cover image for The state you've never needed

The state you've never needed

Pragmatic Maciej on January 12, 2021

Every application has a state. State represents our application data and changes over time. Wikipedia describes state as: A computer program stor...
Collapse
 
artydev profile image
artydev • Edited

Nice thank tout
Everytime, I see post about State
I suggest to give an eye to Meiosis pattern

Collapse
 
macsikora profile image
Pragmatic Maciej

Can you elaborate? I totally don't know what you mean 😉

Collapse
 
olivierjm profile image
Olivier JM Maniraho • Edited

I think it is this one meiosis.js.org/
I haven't read much about it though.

Thread Thread
 
artydev profile image
artydev

Read it, you won't regret it 🙂

Thread Thread
 
merri profile image
Vesa Piittinen • Edited

Not a fan. I've seen people convert to stream based centralized state management and it hasn't worked well from performance perspective. Might be that they've done something wrong, but haven't seen them being able to fix the issue and it's been 1½ years since the change. They did the change because it resulted to "shorter and neater code".

Thread Thread
 
macsikora profile image
Pragmatic Maciej

Yes, in my experience we always should start from less expressive tool and only if it doesn't work for us search for more sophisticated solutions.

Collapse
 
artydev profile image
artydev

Excuse-me,
Here is a link to this concept
Meiosis
You can apply it to any front-end framework you want

Thread Thread
 
macsikora profile image
Pragmatic Maciej

Thanks. Took a look, looks very interesting.

Thread Thread
 
artydev profile image
artydev

😊 yes it is
Once you try it, you will adopt it

Collapse
 
artydev profile image
artydev

I have posted several articles on it on devto,
here is one or them reactmeio
Regards

Collapse
 
meereenee profile image
Enes Kahrovic

Thank you for such an excellent series.
Just one small point. React can help us with delaying the evaluation:

const lionExists = useMemo(() =>
animals.some(animal => animal.type === 'lion'), [animals]);

So, it will be recalculated only when animals is changed.

Collapse
 
macsikora profile image
Pragmatic Maciej

Yes, that is very good comment. Thank you Enes.

Collapse
 
remshams profile image
Mathias Remshardt

In regard to the topic of calculated/derived state properties, I always ask myself the two questions:

  • Does it change together
  • Is it not based on coincidence

In case the answer is yes to both questions then one property can be derived from the other (the base one).

This has served me well so far ;)

Collapse
 
higharc91 profile image
Jarred Beverly

Thanks very informative!

Collapse
 
mcsee profile image
Maxi Contieri

amazing article!

state modelling is TOO important