{"id":18652736,"url":"https://github.com/meowtec/babel-plugin-react-binding","last_synced_at":"2025-04-11T16:31:42.344Z","repository":{"id":73762704,"uuid":"104577692","full_name":"meowtec/babel-plugin-react-binding","owner":"meowtec","description":"Two way binding sugar for React","archived":false,"fork":false,"pushed_at":"2017-09-30T17:40:56.000Z","size":74,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T06:02:12.041Z","etag":null,"topics":["babel","react","twoway"],"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/meowtec.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":"2017-09-23T15:26:30.000Z","updated_at":"2019-01-10T10:08:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"bb40bb84-6604-42ab-81da-48b06e81c504","html_url":"https://github.com/meowtec/babel-plugin-react-binding","commit_stats":{"total_commits":15,"total_committers":2,"mean_commits":7.5,"dds":0.06666666666666665,"last_synced_commit":"bd734b651d62023924fad2de9b77e3a7bcc57b32"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meowtec%2Fbabel-plugin-react-binding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meowtec%2Fbabel-plugin-react-binding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meowtec%2Fbabel-plugin-react-binding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meowtec%2Fbabel-plugin-react-binding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meowtec","download_url":"https://codeload.github.com/meowtec/babel-plugin-react-binding/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248441225,"owners_count":21103947,"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":["babel","react","twoway"],"created_at":"2024-11-07T07:08:14.852Z","updated_at":"2025-04-11T16:31:42.336Z","avatar_url":"https://github.com/meowtec.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# babel-plugin-react-binding\n\nTwo way binding sugar for React.\n\n![Travis](https://travis-ci.org/meowtec/babel-plugin-react-binding.svg?branch=master)\n![codecov](https://codecov.io/gh/meowtec/babel-plugin-react-binding/branch/master/graph/badge.svg)\n\n## Usage\n\n#### install\n\n```\nnpm i babel-plugin-react-binding --save-dev\n```\n\n####  add `react-binding` to `.babelrc`\n\n```js\n{\n  \"plugins\": [\n    [\"react-binding\", {\n      // options\n    }]\n  ]\n}\n```\n\n#### use binding in React JSX!\n\n```javascript\n\u003cdiv\u003e\n  \u003cinput binding={this.state.inputValue}\u003e\n  \u003cDialog binding={this.state.dialogOpen}\u003e\n\u003c/div\u003e\n```\n\n#### binding to redux example\n\n```javascript\nclass App extends React.Component {\n  render () {\n    return (\n      \u003cinput id='input' binding={this.props.input} /\u003e\n    )\n  }\n}\n\nexport default connect(\n  state =\u003e state.form,\n  dispatch =\u003e ({\n    onChange (value, key) {\n      dispatch({\n        type: 'UPDATE_FORM',\n        key,\n        value,\n      })\n    },\n  })\n)(App)\n```\n\n## Principle\n\n`react-binding` will automatically add `value` and `onChange` props to React Element. After the event triggered, `react-binding` will receive the new value, and execute `setState()` to update the value.\n\nYou can think of it as (if you write by hand):\n\n```javascript\n\u003cinput\n  value={this.state.inputValue}\n  onChange={e =\u003e this.setState({ inputValue: e.target.value })}\n\u003e\n```\n\n## Options\n\nUse babel option to custom the prop name (default `binding`)\n\n```json\n{\n  \"plugins\": [\n    [\"react-binding\", {\n      \"attrName\": \"bindModel\"\n    }]\n  ]\n}\n```\n\nThen the jsx code may be like:\n\n```javascript\n\u003cinput bindModel={this.state.inputValue}\u003e\n```\n\n## Custom Component\n\nBy default, `react-binding` use `value` and `onChange` as default prop names for two-way binding (except radio and checkbox, they use `checked`). But some custom component may use another prop name, for example `onInput`.\n\nUse static property `bindingDescriptor` for adaptation.\n\n```javascript\nCustomComponent.bindingDescriptor = {\n  prop: 'number',\n  event: 'onInput',\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeowtec%2Fbabel-plugin-react-binding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeowtec%2Fbabel-plugin-react-binding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeowtec%2Fbabel-plugin-react-binding/lists"}