{"id":23387366,"url":"https://github.com/chikara-chan/babel-plugin-react-scope-binding","last_synced_at":"2025-07-19T06:32:35.512Z","repository":{"id":100157126,"uuid":"82900529","full_name":"chikara-chan/babel-plugin-react-scope-binding","owner":"chikara-chan","description":"🍖 Babel plugin for React component to take event handler to bind context automatically.","archived":false,"fork":false,"pushed_at":"2018-10-26T06:22:59.000Z","size":98,"stargazers_count":21,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-11T18:32:13.820Z","etag":null,"topics":["babel","babel-plugin"],"latest_commit_sha":null,"homepage":"https://chikara-chan.github.io/babel-plugin-react-scope-binding/","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/chikara-chan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-02-23T07:56:58.000Z","updated_at":"2022-02-18T07:57:37.000Z","dependencies_parsed_at":"2023-07-25T23:31:13.514Z","dependency_job_id":null,"html_url":"https://github.com/chikara-chan/babel-plugin-react-scope-binding","commit_stats":{"total_commits":61,"total_committers":3,"mean_commits":"20.333333333333332","dds":0.06557377049180324,"last_synced_commit":"400ce932a61498bf952562b86689557ff38dc9da"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/chikara-chan/babel-plugin-react-scope-binding","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chikara-chan%2Fbabel-plugin-react-scope-binding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chikara-chan%2Fbabel-plugin-react-scope-binding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chikara-chan%2Fbabel-plugin-react-scope-binding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chikara-chan%2Fbabel-plugin-react-scope-binding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chikara-chan","download_url":"https://codeload.github.com/chikara-chan/babel-plugin-react-scope-binding/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chikara-chan%2Fbabel-plugin-react-scope-binding/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265506711,"owners_count":23778805,"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","babel-plugin"],"created_at":"2024-12-22T01:15:46.884Z","updated_at":"2025-07-19T06:32:35.447Z","avatar_url":"https://github.com/chikara-chan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# babel-plugin-react-scope-binding\n\nBabel plugin for React component to take event handler to bind context automatically.\n\n[![Travis branch](https://img.shields.io/travis/chikara-chan/babel-plugin-react-scope-binding/master.svg)](https://travis-ci.org/chikara-chan/babel-plugin-react-scope-binding)\n[![npm](https://img.shields.io/npm/v/babel-plugin-react-scope-binding.svg)](https://www.npmjs.com/package/babel-plugin-react-scope-binding)\n[![npm](https://img.shields.io/npm/l/babel-plugin-react-scope-binding.svg)](https://github.com/chikara-chan/babel-plugin-react-scope-binding/blob/master/LICENSE)\n\n## Installation\n\n```bash\n$ npm install babel-plugin-react-scope-binding --save-dev\n```\n\n## Motivation\n\nWhen you are building a React component, you have to be careful about event handler. In component, class methods are not bound by default. If you forget to bind `this.handleClick` and pass it to onClick, this will be undefined when the function is actually called.\n\nTherefore, you have to bind the event handler in constructor method, like this,\n\n``` jsx\nclass Header extends React.Component{\n  constructor() {\n    super()\n    this.handleClick = this.handleClick.bind(this) // binding method\n  }\n  handleClick(e) {\n    this.setSate({\n      key: 'value'\n    })\n  }\n  render() {\n    return (\n      \u003cdiv onClick={this.handleClick}\u003e\u003c/div\u003e\n    )\n  }\n}\n\n```\n\nOh shit! It's so troublesome.\nSo, this plugin is born to resolve these thorny problems.\nWith this plugin, you can easily code without caring about context.\n\nInstead,\n\n``` jsx\nclass Header extends React.Component{\n  constructor() {\n    super()\n    // needn't binding method\n  }\n  handleClick(e) {\n    this.setSate({\n      key: 'value'\n    })\n  }\n  render() {\n    return (\n      \u003cdiv onClick={this.handleClick}\u003e\u003c/div\u003e\n    )\n  }\n}\n```\n\n## Usage\n\nWrite via [babelrc](https://babeljs.io/docs/usage/babelrc/).\n\n``` json\n// .babelrc\n{\n  \"plugins\": [\n    [\"react-scope-binding\", {\n      \"propPrefix\": \"on\",\n      \"advanced\": true\n    }]\n  ]\n}\n\n```\n\n#### Options\n\nName | Type | Default | Description\n--- | --- | --- | ---\npropPrefix | String \\| Array | 'on' | Tell plugin what the JSX attributes need binding, default with 'on' prefix, e.g. onClick, onChange. You can also pass an Array to this option, such as ['on', '...']\nadvanced | Boolean | false | Enable advanced usage. In some situation, you want to pass value to event handler. With this option enabled, you can easily write a code such as `\u003cdiv onClick={this.handleClick(item)}\u003e\u003c/div\u003e`. Plugin will auto transpile it to `\u003cdiv onClick={(e) =\u003e {this.handleClick(e, item)}\u003e\u003c/div\u003e`\n\n## Links\n\n[https://chikara-chan.github.io/babel-plugin-react-scope-binding/](https://chikara-chan.github.io/babel-plugin-react-scope-binding/)\n\n## License\n\nReleased under the [MIT](https://github.com/chikara-chan/babel-plugin-react-scope-binding/blob/master/LICENSE) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchikara-chan%2Fbabel-plugin-react-scope-binding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchikara-chan%2Fbabel-plugin-react-scope-binding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchikara-chan%2Fbabel-plugin-react-scope-binding/lists"}