Better way to call both actions and state through useShallow #2543
Unanswered
ImamJanjua
asked this question in
General
Replies: 1 comment
-
I would prefer something like this, but anything would be fine: const useFooState = create((set) => ({
foo: 'foo',
bar: 'bar',
setFoo: () => { /* ... */ },
setBoo: () => { /* ... */ },
}));
const Component = () => {
const foo = useFooStore((state) => state.foo);
const bar = useFooStore((state) => state.bar);
const { setFoo, setBar } = useFooStore.getState();
// ...
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, at the moment i am getting my states and actions from from useShallow hook at same way to get all on one swipe, but is there a better way?
const [ createStartSlot, setCreateStartSlot, createSlotLength, setCreateSlotLength, createEndSlot, setCreateEndSlot ] = useCalendarStore( useShallow((state) => [ state.createStartSlot, state.setCreateStartSlot, state.createSlotLength, state.setCreateSlotLength, state.createEndSlot, state.setCreateEndSlot, ]), );
Beta Was this translation helpful? Give feedback.
All reactions