meteor / react-packages

Meteor packages for a great React developer experience
http://guide.meteor.com/react.html
Other
574 stars 159 forks source link

Add react-meteor-state/use-meteor-state #333

Open CaptainN opened 3 years ago

CaptainN commented 3 years ago

This adds the react-meteor-state package! This package contains the useMeteorState hook, which provides a state manager like React's build in useState built on Meteor's Reload package. The result, state persists between page refreshes during development and hot-code-push!

The only downside is that you have to name each use with a globally unique name - so this is not a direct replacement for useState.

TODO:

filipenevola commented 2 years ago

@CaptainN how can we help here?

CaptainN commented 2 years ago

This just needs documentation and tests. (Or an executive decision to skip those)

CaptainN commented 2 years ago

~This useId hook has the potential to make this a full blown meteor flavored replacement for useState. I might even be inclined to provide one for useReducer as well.~ (Er maybe not? I think I jumped the gun. The ID it generates would not survive a reload.... nm)

Grubba27 commented 2 years ago

How would it be an example of the use of this? I could probably try to help to test, but creating a good readme is an easy win. Do you have an example of using this custom hook?

CaptainN commented 2 years ago

It's almost the same as using useState except you need to name the object with a globally unique string. You would use this for something like form input - then when the page refreshes due to a meteor refresh, that data should be restored. That would work through both development refreshes and during hot-code pushes.

StorytellerCZ commented 10 months ago

Have been using this in production for over two years now without a problem. Let's get this finished please!