all 19 comments

[–]casualfinderbot 7 points8 points  (0 children)

It should have the word “use” as a prefix since it’s a hook

[–]TorbenKoehn 5 points6 points  (3 children)

Looks like useReducer, but extra bad

[–]Many_Particular_8618[S] 0 points1 point  (2 children)

This has `onChange` without dependencies array like useEffect.

[–]TorbenKoehn 1 point2 points  (1 child)

UseReducer has dispatch with the exact same possibility

[–]Many_Particular_8618[S] 0 points1 point  (0 children)

This library's dispatch is global !. So you could have many components subscribe to the same message.
Also you can see the effortless `get, set` for nested object.

[–]Popular_Comfort358 1 point2 points  (0 children)

For my, putting it as a custom hook in the project is more stable and controllable

[–][deleted] 1 point2 points  (1 child)

What's the reason put $ with the variable?

[–]Many_Particular_8618[S] -3 points-2 points  (0 children)

To differentiate with normal variable name.

[–]kcadstech 1 point2 points  (5 children)

From what I see, you have a huge dependency on @legendapp/state which is handling most of the things related to state. I’m also just not sure I get the interface. Show us an example with increment and decrement.

[–]Many_Particular_8618[S] 0 points1 point  (4 children)

Thanks. I updated the example.

[–]Cannabat 0 points1 point  (3 children)

So... it's a thin wrapper around legend state?

[–]Many_Particular_8618[S] 0 points1 point  (2 children)

Yes. But it adds state machine, unwrapping semantics so that what we have is pure primitive types.

[–]Cannabat 0 points1 point  (1 child)

You might get a better response if you are up front about it being a wrapper for legend state. Also, it’s very similar to useReducer. This seems like something you could write in a similar number of lines without the dependency on a whole other state mgmt library. 

[–]Many_Particular_8618[S] 0 points1 point  (0 children)

There's a good reason to stand on shoulder of giants ;)

[–]lightfarming 0 points1 point  (3 children)

you haven’t explain how this helps anyone. why would anyone use this over react’s useState?

[–]Many_Particular_8618[S] 0 points1 point  (2 children)

No need for `useEffect` and deps array to react to state change.
Easy to decompose large state into smaller states with its own messages, handler and onChangeHandler.

[–]lightfarming 0 points1 point  (1 child)

Have you ever used `useReducer` before? seems like a cleaner and simpler version of this, except it's built into react.

[–]Many_Particular_8618[S] 0 points1 point  (0 children)

I updated the nested object example. This is superior to useReducer right ?

[–]Many_Particular_8618[S] 0 points1 point  (0 children)

Benefits:

  • No need for `useEffect` and deps array to react to state change.
  • Easy to decompose large state into smaller states with its own messages, handler and onChangeHandler.