{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "useGetState", "title": "useGetState", "description": "useGetState hook", "registryDependencies": [ "https://shadcn-ahooks.vercel.app/r/useLatest.json" ], "files": [ { "path": "packages/hooks/src/useGetState/index.ts", "content": "import type { Dispatch, SetStateAction } from 'react';\nimport { useState, useCallback } from 'react';\nimport useLatest from '../useLatest';\n\ntype GetStateAction = () => S;\n\nfunction useGetState(\n initialState: S | (() => S),\n): [S, Dispatch>, GetStateAction];\nfunction useGetState(): [\n S | undefined,\n Dispatch>,\n GetStateAction,\n];\nfunction useGetState(initialState?: S) {\n const [state, setState] = useState(initialState);\n const stateRef = useLatest(state);\n\n const getState = useCallback(() => stateRef.current, []);\n\n return [state, setState, getState];\n}\n\nexport default useGetState;\n", "type": "registry:file", "target": "src/hooks/ahooks/useGetState/index.ts" } ], "type": "registry:hook" }