{"id":18666796,"url":"https://github.com/sunnshare/react-hooks","last_synced_at":"2025-11-06T13:30:35.372Z","repository":{"id":221714679,"uuid":"755182888","full_name":"sunnshare/react-hooks","owner":"sunnshare","description":"react-hooks","archived":false,"fork":false,"pushed_at":"2024-02-22T15:05:40.000Z","size":133,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-27T18:11:54.435Z","etag":null,"topics":["usecallback","usecontext","useeffect","uselayouteffect","usememo","usereducer","usestate"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/sunnshare.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-09T15:45:15.000Z","updated_at":"2024-02-22T15:13:40.000Z","dependencies_parsed_at":"2024-11-07T08:49:14.022Z","dependency_job_id":null,"html_url":"https://github.com/sunnshare/react-hooks","commit_stats":null,"previous_names":["sunnshare/react-hooks"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunnshare%2Freact-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunnshare%2Freact-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunnshare%2Freact-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunnshare%2Freact-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunnshare","download_url":"https://codeload.github.com/sunnshare/react-hooks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239493676,"owners_count":19647995,"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":["usecallback","usecontext","useeffect","uselayouteffect","usememo","usereducer","usestate"],"created_at":"2024-11-07T08:34:05.946Z","updated_at":"2025-11-06T13:30:35.324Z","avatar_url":"https://github.com/sunnshare.png","language":"JavaScript","readme":"### useState\n\n- params (state)，return [state, setState]\n- 内部采用闭包，用 currentIndex 去记录 state 在 hookStates 数组中的位置\n- 调用 setState 设置值时，将 state 改变，并重置 hookIndex，重新渲染组件\n\n### useMemo\n\n- params (() =\u003e {key: value}, [deps])，return {key: value}\n- 初始以 [{key, value}, [deps]]形式 缓存在 hookStates 中\n- 读取时比较前后 deps 的变化，不变则读取缓存，发生改变则重新缓存\n\n### useCallback\n\n- params (() =\u003e fn, [deps])，return () =\u003e fn\n- 与 useMemo 实现基本一致\n\n### useEffect\n\n- params (callback, [deps])，return callback()\n- 初始以 [callback(), [deps]]形式 缓存在 hookStates 中\n- 读取时比较前后 deps 的变化，发生改变则调用 destroy 函数，重新缓存销毁函数和依赖\n\n### useLayoutEffect\n\n- 与 useEffect 基本一致，useEffect 用的是宏任务，useLayoutEffect 用的是微任务\n\n### useReducer\n\n- 与 useState 基本一致，在 hookStates 中记录了一个 reducer(state,action)\n\n### useContext\n\n- React.createContext() 会返回一个 context 将数据挂载到 \\_currentValue 上\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunnshare%2Freact-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunnshare%2Freact-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunnshare%2Freact-hooks/lists"}