{"id":23715437,"url":"https://github.com/orzhtml/react-native-orzhtml-usecom","last_synced_at":"2026-02-10T10:30:19.549Z","repository":{"id":41389822,"uuid":"509381659","full_name":"orzhtml/react-native-orzhtml-usecom","owner":"orzhtml","description":"react react-native：hooks 的状态 use 扩展","archived":false,"fork":false,"pushed_at":"2023-08-28T07:56:08.000Z","size":576,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T09:16:43.310Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orzhtml.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-01T08:40:31.000Z","updated_at":"2022-07-01T09:37:53.000Z","dependencies_parsed_at":"2023-01-27T17:00:23.011Z","dependency_job_id":null,"html_url":"https://github.com/orzhtml/react-native-orzhtml-usecom","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orzhtml%2Freact-native-orzhtml-usecom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orzhtml%2Freact-native-orzhtml-usecom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orzhtml%2Freact-native-orzhtml-usecom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orzhtml%2Freact-native-orzhtml-usecom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orzhtml","download_url":"https://codeload.github.com/orzhtml/react-native-orzhtml-usecom/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239808052,"owners_count":19700439,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-30T20:56:22.747Z","updated_at":"2026-02-10T10:30:19.456Z","avatar_url":"https://github.com/orzhtml.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-orzhtml-usecom\n\nreact react-native typescript：hooks 的状态 use 扩展\n\n\u003e 如果你发现该项目对你有用，请加个星吧。\n\n## Install\n\n`yarn add react-native-orzhtml-usecom`\n\n## hooks\n\n- [useStateCB](#useStateCB)\n\n让你可以安全地使用 react 的 state，它的值就是你想要的值，而不是陈旧的值。并且也拥有了 callback 的能力。\n\n- [useSingleState（推荐使用）](#useSingleState)\n\n使用类似于 `class` 形式的 `this.state` 和 `this.setState` 的方式来使用 `state`。同样可以安全地使用 state，并且拥有 callback 能力\n\n- [useSingleInstanceVar（推荐使用）](#useSingleInstanceVar)\n\n（推荐使用）将所有实例变量声明在一起，并以更接近实例变量的方式使用\n\n\n## 使用\n\n### useStateCB\n\n让你可以安全地使用 react 的 state，它的值就是你想要的值，而不是陈旧的值。并且也拥有了 callback 的能力。\n\n```\n# Example\n\nimport React from 'react'\nimport { View, Text, Button } from 'react-native'\n\nimport { useStateCB } from 'react-native-orzhtml-usecom'\n\nexport const UseStateCBDemoComp = () =\u003e {\n  const [getCount, setCount] = useStateCB(0)\n\n  const doSomeActions = () =\u003e {\n    console.log('Current count:', getCount())\n  }\n\n  return (\n    \u003cView\u003e\n      \u003cText\u003e{getCount()}\u003c/Text\u003e\n      \u003cButton \n        onPress={() =\u003e {\n      \t  setCount(getCount() + 1, doSomeActions)\n        }}\n        title=\"Increase\"\n      /\u003e\n    \u003c/View\u003e\n  );\n};\n```\n\n### useSingleState\n\n（推荐使用）使用类似于 `class` 形式的 `this.state` 和 `this.setState` 的方式来使用 `state`。同样可以安全地使用 state，并且拥有 callback 能力\n\n```\n# Example\n\nimport React from 'react'\nimport { View, Text, Button } from 'react-native'\n\nimport { useSingleState } from 'react-native-orzhtml-usecom'\n\nexport const UseSingleStateDemoComp = () =\u003e {\n  const [state, setState] = useSingleState({\n    count: 0,\n    time: +new Date()\n  })\n\n  const doSomeActions = () =\u003e {\n    console.log(\"Current count:\", state.count)\n  }\n\n  return (\n    \u003cView\u003e\n      \u003cText\u003euseSingleState\u003c/Text\u003e\n\n      \u003cText\u003e{state.count} {state.time}\u003c/Text\u003e\n\n      \u003cButton\n        onPress={() =\u003e {\n        \t  setState(\n            {\n              count: state.count + 1\n            },\n            doSomeActions\n          )\n        }}\n        title=\"Increase\"\n      /\u003e\n      \u003cButton\n        onPress={() =\u003e {\n          setState({\n            time: +new Date()\n          })\n        }}\n        title=\"Change Time\"\n      /\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n### useSingleInstanceVar\n\n（推荐使用）将所有实例变量声明在一起，并以更接近实例变量的方式使用\n\n```\n# Example\n\nimport React from 'react'\nimport { View, Text, Button } from 'react-native'\n\nimport { useSingleInstanceVar, useSingleState } from 'react-native-orzhtml-usecom'\n\nexport const UseSingleInstanceVarDemoComp = () =\u003e {\n  const instanceVal = useSingleInstanceVar({\n    interval: null\n  })\n\n  const [state, setState] = useSingleState({ count: 0 })\n\n  const start = () =\u003e {\n    stop()\n    instanceVal.interval = setInterval(\n      () =\u003e setState({ count: state.count + 1 }),\n      1000\n    )\n  }\n\n  const stop = () =\u003e {\n    const interval = instanceVal.interval\n    interval \u0026\u0026 clearInterval(interval)\n  }\n\n  return (\n    \u003cView\u003e\n      \u003cText\u003e{state.count}\u003c/Text\u003e\n      \u003cButton onPress={start} title=\"Start\" /\u003e\n      \u003cButton onPress={stop} title=\"Stop\" /\u003e\n    \u003c/View\u003e\n  )\n}\n```\n\n### useDebounce\n防抖\n\n```\n# Example\n...\nimport { useDebounce } from 'react-native-orzhtml-usecom'\nconst Home = (props) =\u003e {\n  const [a, setA] = useState(0)\n  const [b, setB] = useState(0)\n  const [cancel] = useDebounce(() =\u003e {\n    setB(a)\n  }, 2000, [a])\n\n  const changeIpt = (e) =\u003e {\n    setA(e.target.value)\n  }\n  return \u003cView\u003e\n    \u003cTextInput onChangeText={changeIpt} /\u003e\n    \u003cText\u003e{ b } { a }\u003c/Text\u003e\n  \u003c/View\u003e\n}\n```\n\n### useThrottle\n节流\n\n```\n# Example\n...\nimport { useThrottle } from 'react-native-orzhtml-usecom'\nconst Home = (props) =\u003e {\n  const [a, setA] = useState(0)\n  const [b, setB] = useState(0)\n  const [cancel] = useThrottle(() =\u003e {\n    setB(a)\n  }, 2000, [a])\n\n  const changeIpt = (e) =\u003e {\n    setA(e.target.value)\n  }\n  return \u003cView\u003e\n    \u003cTextInput onChangeText={changeIpt} /\u003e\n    \u003cText\u003e{ b } { a }\u003c/Text\u003e\n    \u003cButton title=\"cancel\" onPress={cancel}\u003e\n  \u003c/View\u003e\n}\n```\n\n### useFormChange\n表单/表头搜素hooks\n\n```\n# Example\n...\n\nimport { useFormChange } from 'react-native-orzhtml-usecom'\nconst [formData, setFormItem, reset] = useFormChange()\n\n...\n\n// const [formData, setFormItem, reset] = useFormChange({ name: '小明', sex: '男'})\n```\n\n### useInterval\nuseInterval 定时器\n\n```\n# Example\n...\n\nimport { useInterval } from 'react-native-orzhtml-usecom'\nconst [interval, intervalClear] = useInterval()\n\n...\n\ninterval(() =\u003e {\n  console.log(1)\n}, 1000, true)\n```\n\n### useTimeout\nuseTimeout 定时器\n\n```\n# Example\n...\n\nimport { useTimeout } from 'react-native-orzhtml-usecom'\nconst [timeout, timeoutClear] = useTimeout()\n\n...\n\ntimeout(() =\u003e {\n  console.log(1)\n}, 1000)\n```\n\n### useTableRequset\n列表 表格数据查询\n\n```\n# Example\n...\n// getList 接口\nconst [tableData, handerChange, handerRefresh] = useTableRequest(query, getList)\nconst { page ,pageSize,totalCount ,list } = tableData\n// 传入的接口数据返回要求如下，否则容易出错：\n//  {\n//     list: [],\n//     totalCount: 0,\n//     pageSize: 10,\n//     page: 1,\n//   }\n```\n\n### useUpdate\n更新\n\n```\n# Example\n...\n// getList 接口\nconst update = useUpdate()\n\n return \u003cView\u003e\n    \u003cButton title=\"更新\" onPress={update}\u003e\n  \u003c/View\u003e\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forzhtml%2Freact-native-orzhtml-usecom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forzhtml%2Freact-native-orzhtml-usecom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forzhtml%2Freact-native-orzhtml-usecom/lists"}