{"id":13701322,"url":"https://github.com/yyx990803/vue-hooks","last_synced_at":"2025-05-04T21:30:44.211Z","repository":{"id":49783984,"uuid":"154927626","full_name":"yyx990803/vue-hooks","owner":"yyx990803","description":"Experimental React hooks implementation in Vue","archived":true,"fork":false,"pushed_at":"2020-04-29T19:59:15.000Z","size":17,"stargazers_count":1595,"open_issues_count":10,"forks_count":67,"subscribers_count":39,"default_branch":"master","last_synced_at":"2024-11-13T07:35:46.200Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yyx990803.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-27T04:58:21.000Z","updated_at":"2024-10-02T17:15:00.000Z","dependencies_parsed_at":"2022-09-03T00:00:32.725Z","dependency_job_id":null,"html_url":"https://github.com/yyx990803/vue-hooks","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/yyx990803%2Fvue-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yyx990803%2Fvue-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yyx990803%2Fvue-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yyx990803%2Fvue-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yyx990803","download_url":"https://codeload.github.com/yyx990803/vue-hooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252403684,"owners_count":21742410,"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-08-02T20:01:29.303Z","updated_at":"2025-05-04T21:30:43.943Z","avatar_url":"https://github.com/yyx990803.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# **!!! ARCHIVED !!!**\n\nVue now has its own hooks inspired API for composing logic: https://composition-api.vuejs.org/\n\nThis PoC has completed its purpose and will no longer be updated.\n\n---\n\n# vue-hooks\n\nPOC for using [React Hooks](https://reactjs.org/docs/hooks-intro.html) in Vue. Totally experimental, don't use this in production.\n\n[Live Demo](https://codesandbox.io/s/jpqo566289)\n\n### React-style Hooks\n\n``` js\nimport Vue from \"vue\"\nimport { withHooks, useState, useEffect } from \"vue-hooks\"\n\n// a custom hook...\nfunction useWindowWidth() {\n  const [width, setWidth] = useState(window.innerWidth)\n  const handleResize = () =\u003e {\n    setWidth(window.innerWidth)\n  };\n  useEffect(() =\u003e {\n    window.addEventListener(\"resize\", handleResize)\n    return () =\u003e {\n      window.removeEventListener(\"resize\", handleResize)\n    }\n  }, [])\n  return width\n}\n\nconst Foo = withHooks(h =\u003e {\n  // state\n  const [count, setCount] = useState(0)\n\n  // effect\n  useEffect(() =\u003e {\n    document.title = \"count is \" + count\n  })\n\n  // custom hook\n  const width = useWindowWidth()\n\n  return h(\"div\", [\n    h(\"span\", `count is: ${count}`),\n    h(\n      \"button\",\n      {\n        on: {\n          click: () =\u003e setCount(count + 1)\n        }\n      },\n      \"+\"\n    ),\n    h(\"div\", `window width is: ${width}`)\n  ])\n})\n\n// just so you know this is Vue...\nnew Vue({\n  el: \"#app\",\n  render(h) {\n    return h(\"div\", [h(Foo), h(Foo)])\n  }\n})\n```\n\n### Vue-style Hooks\n\nAPI that maps Vue's existing API.\n\n``` js\nimport {\n  withHooks,\n  useData,\n  useComputed,\n  useWatch,\n  useMounted,\n  useUpdated,\n  useDestroyed\n} from \"vue-hooks\"\n\nconst Foo = withHooks(h =\u003e {\n  const data = useData({\n    count: 0\n  })\n\n  const double = useComputed(() =\u003e data.count * 2)\n\n  useWatch(() =\u003e data.count, (val, prevVal) =\u003e {\n    console.log(`count is: ${val}`)\n  })\n\n  useMounted(() =\u003e {\n    console.log('mounted!')\n  })\n  useUpdated(() =\u003e {\n    console.log('updated!')\n  })\n  useDestroyed(() =\u003e {\n    console.log('destroyed!')\n  })\n\n  return h('div', [\n    h('div', `count is ${data.count}`),\n    h('div', `double count is ${double}`),\n    h('button', { on: { click: () =\u003e {\n      // still got that direct mutation!\n      data.count++\n    }}}, 'count++')\n  ])\n})\n```\n\n### Usage in Normal Vue Components\n\n``` js\nimport { hooks, useData, useComputed } from 'vue-hooks'\n\nVue.use(hooks)\n\nnew Vue({\n  template: `\n    \u003cdiv @click=\"data.count++\"\u003e\n      {{ data.count }} {{ double }}\n    \u003c/div\u003e\n  `,\n  hooks() {\n    const data = useData({\n      count: 0\n    })\n\n    const double = useComputed(() =\u003e data.count * 2)\n\n    return {\n      data,\n      double\n    }\n  }\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyyx990803%2Fvue-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyyx990803%2Fvue-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyyx990803%2Fvue-hooks/lists"}