{"id":15314622,"url":"https://github.com/barelyhuman/babel-plugin-mutable-react-state","last_synced_at":"2025-07-19T12:38:35.778Z","repository":{"id":45244082,"uuid":"438484295","full_name":"barelyhuman/babel-plugin-mutable-react-state","owner":"barelyhuman","description":"(WIP) transform mutable variables to react-state","archived":false,"fork":false,"pushed_at":"2022-01-03T23:36:56.000Z","size":50,"stargazers_count":7,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-04-15T02:16:22.997Z","etag":null,"topics":["babel","mutable","react","reactjs","state"],"latest_commit_sha":null,"homepage":"https://barelyhuman.github.io/babel-plugin-mutable-react-state/","language":"TypeScript","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/barelyhuman.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}},"created_at":"2021-12-15T03:40:04.000Z","updated_at":"2023-09-06T23:53:06.000Z","dependencies_parsed_at":"2022-08-31T03:11:05.370Z","dependency_job_id":null,"html_url":"https://github.com/barelyhuman/babel-plugin-mutable-react-state","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/barelyhuman/babel-plugin-mutable-react-state","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barelyhuman%2Fbabel-plugin-mutable-react-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barelyhuman%2Fbabel-plugin-mutable-react-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barelyhuman%2Fbabel-plugin-mutable-react-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barelyhuman%2Fbabel-plugin-mutable-react-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barelyhuman","download_url":"https://codeload.github.com/barelyhuman/babel-plugin-mutable-react-state/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barelyhuman%2Fbabel-plugin-mutable-react-state/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265934262,"owners_count":23852092,"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","mutable","react","reactjs","state"],"created_at":"2024-10-01T08:46:21.829Z","updated_at":"2025-07-19T12:38:35.754Z","avatar_url":"https://github.com/barelyhuman.png","language":"TypeScript","readme":"# babel-plugin-mutable-react-state\n\n\u003e (WIP) Use mutable variable declarations as state in react\n\n[![Test](https://github.com/barelyhuman/babel-plugin-mutable-react-state/actions/workflows/test.yml/badge.svg)](https://github.com/barelyhuman/babel-plugin-mutable-react-state/actions/workflows/test.yml)\n\n**UNSTABLE**\n**The plugin is still under development so isn't recommended for production**\n\n## Caveats (for now)\n\nCheck [this issue](https://github.com/barelyhuman/babel-plugin-mutable-react-state/issues/4)\n\n## Docs\n\n[Web Documentation](https://barelyhuman.github.io/babel-plugin-mutable-react-state/#/)\n\n## Notes\n\n- While the caveats exist due to the extensive types of expressions that javascript has, it's recommended that you use a cloned variable and then just assigned the modification to the reactive variable if you plan to use it right now.\n\n```jsx\nfunction Component() {\n  let $text = ''\n\n  return (\n    \u003c\u003e\n      \u003cinput\n        value={$text}\n        onChange={(e) =\u003e {\n          $text = e.target.value\n          // some code\n\n          // won't work...\n          $text = $text.toUpperCase()\n        }}\n      /\u003e\n    \u003c/\u003e\n  )\n}\n\n// CAN be written as\n\nfunction Component() {\n  let $text = ''\n\n  return (\n    \u003c\u003e\n      \u003cinput\n        value={$text}\n        onChange={(e) =\u003e {\n          const val = e.target.value\n          // some code\n\n          // will work...\n          $text = val.toUpperCase()\n        }}\n      /\u003e\n    \u003c/\u003e\n  )\n}\n```\n\n- This is still react state so you cannot do dependent state updates at once,\n\n```jsx\n// the value of `length` will still be the older value of $text and not the latest one\nchangeHandler(){\n  $text = value\n  $length = $text.length\n}\n\n// you'll still have to consider that dependent values need to be handled with useEffect\n\nuseEffect(()=\u003e{\n  $length = $text.length\n},[$text])\n\nchangeHandler(){\n  $text = value\n}\n```\n\n## Install\n\nThe plugin assumes you already have `jsx` enabled on babel or are using `preset-react` in your setup.\n\n```sh\nnpm i babel-plugin-mutable-react-state\n# or\nyarn add babel-plugin-mutable-react-state\n```\n\n```jsonc\n// .babelrc\n[\n  {\n    \"plugins\": [\"babel-plugin-mutable-react-state\"]\n  }\n]\n```\n\n## Usage\n\nYou write state with a prefix `$` and that's converted to `useState` accordingly.\n\n```jsx\nimport * as React from 'react'\n\nfunction Component() {\n  let $a = 1\n\n  const onPress = () =\u003e {\n    $a += 1\n  }\n\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003e{$a}\u003c/p\u003e\n      \u003cbutton onClick={onPress}\u003ePress\u003c/button\u003e\n    \u003c/div\u003e\n  )\n}\n\n ↓ ↓ ↓ ↓ ↓ ↓\n\nimport * as React from 'react'\n\nfunction Component() {\n  const [a, setA] = React.useState(1)\n\n  const onPress = () =\u003e {\n    setA(a + 1)\n  }\n\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003e{a}\u003c/p\u003e\n      \u003cbutton onClick={onPress}\u003ePress\u003c/button\u003e\n    \u003c/div\u003e\n  )\n}\n```\n\n## License\n\n[MIT](/LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarelyhuman%2Fbabel-plugin-mutable-react-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarelyhuman%2Fbabel-plugin-mutable-react-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarelyhuman%2Fbabel-plugin-mutable-react-state/lists"}