{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-controlled-state",
  "title": "Use controlled state",
  "description": "Hook utility: use-controlled-state",
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/optics/hooks/use-controlled-state.jsx",
      "content": "import * as React from \"react\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useControlledState(props) {\n\tconst { value, defaultValue, onChange } = props;\n\n\tconst [state, setInternalState] = React.useState(\n\t\tvalue !== undefined ? value : defaultValue,\n\t);\n\n\tReact.useEffect(() => {\n\t\tif (value !== undefined) setInternalState(value);\n\t}, [value]);\n\n\tconst setState = React.useCallback(\n\t\t(next, ...args) => {\n\t\t\tsetInternalState(next);\n\t\t\tonChange?.(next, ...args);\n\t\t},\n\t\t[onChange],\n\t);\n\n\treturn [state, setState];\n}\n",
      "type": "registry:lib",
      "target": "hooks/use-controlled-state.jsx"
    }
  ],
  "type": "registry:lib"
}