{"id":16841868,"url":"https://github.com/prevwong/react-vue-component","last_synced_at":"2025-04-11T06:44:05.293Z","repository":{"id":57347515,"uuid":"158576730","full_name":"prevwong/react-vue-component","owner":"prevwong","description":"Create Vue-like components in React (watchers, computed properties etc)","archived":false,"fork":false,"pushed_at":"2019-01-02T17:04:09.000Z","size":17143,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T04:41:21.053Z","etag":null,"topics":["computed","react","reactivity","vue","watcher"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/prevwong.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-11-21T16:27:26.000Z","updated_at":"2024-01-12T06:32:36.000Z","dependencies_parsed_at":"2022-08-28T04:00:49.720Z","dependency_job_id":null,"html_url":"https://github.com/prevwong/react-vue-component","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/prevwong%2Freact-vue-component","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prevwong%2Freact-vue-component/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prevwong%2Freact-vue-component/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prevwong%2Freact-vue-component/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prevwong","download_url":"https://codeload.github.com/prevwong/react-vue-component/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248358549,"owners_count":21090401,"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":["computed","react","reactivity","vue","watcher"],"created_at":"2024-10-13T12:43:16.963Z","updated_at":"2025-04-11T06:44:05.272Z","avatar_url":"https://github.com/prevwong.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-vue-component\n\nBuild Vue-like components in React. Get the goodness of Vue-reactivty system such as watchers and computed properties and remove the need of using React's `setState` completely. \n\n## Installation\n\n`$ npm install --save react-vue-component`\n\n# Basic  Usage\n\n- ```jsx\n  import {Component} from \"react-vue-component\";\n  \n  class App extends Component {\n      state = {\n          name: \"Bob\", \n      }\n      componentDidMount() {\n          this.name = \"Albert\";\n      }\n      watch {\n          name(newName, oldName) {\n              console.log(\"name has changed!\");\n          },\n      }\n      computed {\n          fullName(){\n              return this.name + \" Lolzer\";\n          }\n      }\n      methods {\n          changeName() {\n              // Changing name will also change the computed property fullName\n              this.name = \"John\";\n          }\n      }\n      render() {\n          // states, methods, and computed properties can be accessed directly via `this` just like in Vue\n          const {name, fullName, changeName} = this;\n          \n          return (\n              \u003cdiv\u003e\n                  \u003cp\u003e{name}\u003c/p\u003e\n                  \u003cp\u003e{fullName}\u003c/p\u003e\n                  \u003ca onClick={() =\u003e this.changeName()}\u003eChange my name\u003c/a\u003e  \n              \u003c/div\u003e   \n          )\n      }\n  }\n  ```\n\n## Objects\n\n- In Vue, in order to \"reactively\" add/delete key-value pairs from an object, you will need to use  `set(obj, key, value)`and `delete(obj,key)`respectively.\n\n```jsx\nimport {Component} from \"react-vue-component\";\nclass App extends Component {\n  state = {\n      obj : {\n          name: \"Prev\"\n      }\n  }\n  methods {\n      addToObj() {\n          this.set(this.obj, \"age\", 20); \n      }\n      deleteName() {\n          this.delete(this.obj, \"name\");\n      }\n  }\n  watch {\n      // nested watchers\n      \"obj.name\" : (newName, oldName) =\u003e {\n          console.log(\"Obj.name has changed\");\n      }\n      \"obj.age\" : (newAge, oldAge) =\u003e {\n          console.log(\"Obj.age has changed\");\n      }\n\n  }\n  render() {\n      const {obj} = this;\n      return (\n          \u003cdiv\u003e\n              Object.keys(obj).map(key =\u003e \n                  \u003cp\u003e\u003cstrong\u003e{key}\u003c/strong\u003e: {obj[key]}\u003c/p\u003e\n              ) \n            \u003ca onClick={() =\u003e this.addToObj()}\u003eAdd new key\u003c/a\u003e\n            \u003ca onClick={() =\u003e this.deleteName()}\u003eDelete name\u003c/a\u003e\n          \u003c/div\u003e\n      )\n  }\n}\n```\n\n\n\n## Caveats\n\n-  Behind the scenes,`componentWillMount` is being used to inject Vue's reactivity system thus it is made impossible to overwrite. Instead, use `beforeMount` as an equivalent replacement:\n\n- ```jsx\n  import {Component} from \"react-vue-component\";\n  class App extends Component {\n      beforeMount(){\n          console.log(\"before mount! component hasnt render yet...\")\n      }\n      ...\n  }\n  ```\n\n# Credits\n\n- All credits to the Vue core team for their awesome reactivity system. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprevwong%2Freact-vue-component","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprevwong%2Freact-vue-component","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprevwong%2Freact-vue-component/lists"}