react-packages icon indicating copy to clipboard operation
react-packages copied to clipboard

Add react-meteor-state/use-meteor-state

Open CaptainN opened this issue 4 years ago • 6 comments

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:

  • [ ] tests
  • [x] documentation (readme)

CaptainN avatar May 12 '21 05:05 CaptainN

@CaptainN how can we help here?

filipenevola avatar Dec 03 '21 00:12 filipenevola

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

CaptainN avatar Dec 08 '21 17:12 CaptainN

~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)

CaptainN avatar Mar 24 '22 17:03 CaptainN

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?

Grubba27 avatar Sep 01 '22 19:09 Grubba27

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.

CaptainN avatar Sep 01 '22 19:09 CaptainN

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

StorytellerCZ avatar Jan 14 '24 12:01 StorytellerCZ