function useCreateAtom<T>(getValue, options?): ReadonlyAtom<T>;function useCreateAtom<T>(getValue, options?): ReadonlyAtom<T>;Defined in: preact-store/src/useCreateAtom.ts:27
Creates a stable atom instance for the lifetime of the component.
Pass an initial value to create a writable atom, or a getter function to create a readonly derived atom. This mirrors createAtom, but only creates the atom once per component mount.
T
(prev?) => T
AtomOptions<T>
ReadonlyAtom<T>
function Counter() {
const countAtom = useCreateAtom(0)
const [count, setCount] = useAtom(countAtom)
return (
<button type="button" onClick={() => setCount((prev) => prev + 1)}>
{count}
</button>
)
}function Counter() {
const countAtom = useCreateAtom(0)
const [count, setCount] = useAtom(countAtom)
return (
<button type="button" onClick={() => setCount((prev) => prev + 1)}>
{count}
</button>
)
}function useCreateAtom<T>(initialValue, options?): Atom<T>;function useCreateAtom<T>(initialValue, options?): Atom<T>;Defined in: preact-store/src/useCreateAtom.ts:31
Creates a stable atom instance for the lifetime of the component.
Pass an initial value to create a writable atom, or a getter function to create a readonly derived atom. This mirrors createAtom, but only creates the atom once per component mount.
T
T
AtomOptions<T>
Atom<T>
function Counter() {
const countAtom = useCreateAtom(0)
const [count, setCount] = useAtom(countAtom)
return (
<button type="button" onClick={() => setCount((prev) => prev + 1)}>
{count}
</button>
)
}function Counter() {
const countAtom = useCreateAtom(0)
const [count, setCount] = useAtom(countAtom)
return (
<button type="button" onClick={() => setCount((prev) => prev + 1)}>
{count}
</button>
)
}