{"id":13670372,"url":"https://github.com/DAB0mB/babel-plugin-react-persist","last_synced_at":"2025-04-27T13:32:14.416Z","repository":{"id":66209431,"uuid":"165335805","full_name":"DAB0mB/babel-plugin-react-persist","owner":"DAB0mB","description":"Automatically useCallback() \u0026 useMemo(); memoize inline functions","archived":false,"fork":false,"pushed_at":"2019-01-19T07:00:52.000Z","size":135,"stargazers_count":112,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-15T06:47:23.466Z","etag":null,"topics":["ast","babel","babel-plugin","jsx","react","react-hooks"],"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/DAB0mB.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}},"created_at":"2019-01-12T02:08:06.000Z","updated_at":"2025-02-15T14:15:34.000Z","dependencies_parsed_at":"2023-02-20T21:00:52.129Z","dependency_job_id":null,"html_url":"https://github.com/DAB0mB/babel-plugin-react-persist","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"1cc83c59ff9e36d4cf954a63e4002b22c494c45b"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DAB0mB%2Fbabel-plugin-react-persist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DAB0mB%2Fbabel-plugin-react-persist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DAB0mB%2Fbabel-plugin-react-persist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DAB0mB%2Fbabel-plugin-react-persist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DAB0mB","download_url":"https://codeload.github.com/DAB0mB/babel-plugin-react-persist/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251145620,"owners_count":21543073,"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":["ast","babel","babel-plugin","jsx","react","react-hooks"],"created_at":"2024-08-02T09:00:40.296Z","updated_at":"2025-04-27T13:32:13.765Z","avatar_url":"https://github.com/DAB0mB.png","language":"JavaScript","readme":"[![CircleCI](https://circleci.com/gh/DAB0mB/babel-plugin-react-persist/tree/master.svg?style=svg)](https://circleci.com/gh/DAB0mB/babel-plugin-react-persist/tree/master)\n\n# babel-plugin-react-persist\n\nA Babel plug-in that optimizes your React.Component's implementation by automatically detecting declarations that should persist between rendering phases and replacing them with `useCallback()` and `useMemo()` whenever necessary. This plug-in can also be used to solve excessive processing power caused by using anonymous callbacks provided to JSX element by making them non-anonymous. **Note that this plug-in is experimental and shouldn't be used in production yet**. Compatible with React 16.8-alpha and above (hooks support).\n\n### Example\n\n#### in\n\n```jsx\nexport default ({ data, sortComparator, filterPredicate, history }) =\u003e {\n  const transformedData = data.filter(filterPredicate).sort(sortComparator)\n\n  return (\n    \u003cdiv\u003e\n      \u003cbutton className=\"back-btn\" onClick={() =\u003e history.pop()} /\u003e\n      \u003cul className=\"data-list\"\u003e\n        {transformedData.map(({ id, value }) =\u003e (\n          \u003cli className=\"data-item\" key={id} onClick={() =\u003e history.push(`data/${id}`)}\u003e{value}\u003c/li\u003e\n        ))}\n      \u003c/ul\u003e\n    \u003c/div\u003e\n  )\n}\n```\n\n#### out\n\n```jsx\nlet _anonymousFnComponent, _anonymousFnComponent2\n\nexport default ({ data, sortComparator, filterPredicate, history }) =\u003e {\n  const transformedData = React.useMemo(() =\u003e\n    data.filter(filterPredicate).sort(sortComparator)\n  , [data, data.filter, filterPredicate, sortComparator])\n\n  return React.createElement(_anonymousFnComponent2 = _anonymousFnComponent2 || (() =\u003e {\n    const _onClick2 = React.useCallback(() =\u003e history.pop(), [history, history.pop])\n\n    return (\n      \u003cdiv\u003e\n        \u003cbutton className=\"back-btn\" onClick={_onClick2} /\u003e\n        \u003cul className=\"data-list\"\u003e\n          {transformedData.map(({ id, value }) =\u003e\n            React.createElement(_anonymousFnComponent = _anonymousFnComponent || (() =\u003e {\n              const _onClick = React.useCallback(() =\u003e\n                history.push(`data/${id}`)\n              , [history, history.push, id])\n\n              return (\n                \u003cli className=\"data-item\" key={id} onClick={_onClick}\u003e\n                  {value}\n                \u003c/li\u003e\n              )\n            }), { key: id })\n          )}\n        \u003c/ul\u003e\n      \u003c/div\u003e\n    )\n  }), null)\n}\n```\n\n### Usage\n\n`babel-plugin-react-persist` is installable via NPM (or Yarn):\n\n    $ npm install babel-plugin-react-persist\n\nAdd to `.babelrc` under `plugins` and be sure to load it **before** any JSX transformation related plug-ins.\n\n```json\n{\n  \"presets\": [\"@babel/preset-react\"],\n  \"plugins\": [\"babel-plugin-react-persist\"]\n}\n```\n\n### License\n\nMIT. If you're including this in a repo above 1k stars I would really appreciate it if you could contact me first.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDAB0mB%2Fbabel-plugin-react-persist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDAB0mB%2Fbabel-plugin-react-persist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDAB0mB%2Fbabel-plugin-react-persist/lists"}