| 1 | import type { SetStateAction } from "react"; |
| 2 | |
| 3 | // applySetState mirrors React's setState contract: resolve the next value from |
| 4 | // either a direct value or an updater (prev => next). It lets a zustand store |
| 5 | // expose Dispatch<SetStateAction<T>> setters that are drop-in replacements for |
| 6 | // useState — so migrated call sites, including functional updaters like |
| 7 | // setOpen(v => !v), need no changes. |
| 8 | export function applySetState<T>(prev: T, update: SetStateAction<T>): T { |
| 9 | return typeof update === "function" ? (update as (value: T) => T)(prev) : update; |
| 10 | } |
| 11 |