reinspect icon indicating copy to clipboard operation
reinspect copied to clipboard

store shared between useState

Open cherepanov opened this issue 6 years ago • 1 comments

If useState called with the same id from different points, then value changes are propagated between all calls. This breaks react behavior and very inconvenient if setState is used inside custom hook. Root of evil is useMemo. Is it really required here?

   const [store, reducerId] = useMemo<[EnhancedStore, string | number]>(
       () => [inspectorStore, id],
       []
   )

Possible solution to use generate kind of uuid if id is true or function;

cherepanov avatar Oct 22 '19 11:10 cherepanov

The code you pasted is there force the usage of the first value received (could be done a different way I guess). But that's independent to each instance.

The ID has to be provided on the user side, so that hooks are easier to identify in the devtools than if a generated ID is used. So yes it needs to be chosen carefully.

troch avatar Mar 02 '20 11:03 troch