Complete the code to create a Zustand store with a count state initialized to 0.
import create from 'zustand'; const useStore = create(set => ({ count: [1], increment: () => set(state => ({ count: state.count + 1 })) }));
The initial state for count should be 0 to start counting from zero.
Complete the code to use the Zustand store inside a React component to get the count value.
import React from 'react'; import useStore from './store'; export default function Counter() { const count = useStore([1]); return <div>Count: {count}</div>; }
To get the current count value from the store, select state.count.
Fix the error in the code to correctly update the count state using the increment function from Zustand.
import React from 'react'; import useStore from './store'; export default function Counter() { const increment = useStore([1]); return <button onClick={increment}>Add 1</button>; }
The increment function is used to update the count, so select state.increment.
Fill both blanks to create a Zustand store with a count state and a decrement function that subtracts 1.
import create from 'zustand'; const useStore = create(set => ({ count: [1], decrement: () => set(state => ({ count: state.count [2] 1 })) }));
The count starts at 0, and decrement subtracts 1 using the minus operator.
Fill all three blanks to create a Zustand store with a count state, an increment function, and a reset function that sets count back to 0.
import create from 'zustand'; const useStore = create(set => ({ count: [1], increment: () => set(state => ({ count: state.count [2] 1 })), reset: () => set({ count: [3] }) }));
Count starts at 0, increment adds 1, and reset sets count back to 0.