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

How to get updated object after set() in useMap?

Open SkutinAnton opened this issue 5 years ago • 1 comments

The old store returns

const [store, { set, setAll }] = useMap({
  count: 0,
});

set("count", 1);
store.count; // 0 (return not update store)

setAll(newStore => {
  newStore.count; // 1 (but the store has already been updated)
 ...
}); 

store.count; // 0 (return not update store)

I expect to receive an updated store after using "set()"

A little about versions:

  • OS: macOS High Sierra, Windows 10
  • Browser (vendor and version): Chrome, Firefox, Safari
  • React: 16.12.0
  • react-use: 15.3.3
  • Did this worked in the previous package version? I don't know

SkutinAnton avatar Apr 13 '21 09:04 SkutinAnton

How's this?

//…

const [store, {get,set, setAll}] = useMap({
  count: 0,
});

return (
      <p>{get('count')}</p>
);

//…

satoutanaka avatar Jun 19 '21 04:06 satoutanaka