{"id":23174583,"url":"https://github.com/vscodeshift/react-codemorphs","last_synced_at":"2025-04-05T00:43:26.300Z","repository":{"id":40783795,"uuid":"235735025","full_name":"vscodeshift/react-codemorphs","owner":"vscodeshift","description":"Codemod commands for everyday work with React. All commands support Flow, TypeScript, and plain JS.","archived":false,"fork":false,"pushed_at":"2023-01-05T05:33:22.000Z","size":4053,"stargazers_count":1,"open_issues_count":22,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T09:15:15.606Z","etag":null,"topics":["codemods","jscodeshift","react","refactoring","vscode"],"latest_commit_sha":null,"homepage":"","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/vscodeshift.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-23T06:15:53.000Z","updated_at":"2022-02-09T12:51:59.000Z","dependencies_parsed_at":"2023-02-03T13:47:27.530Z","dependency_job_id":null,"html_url":"https://github.com/vscodeshift/react-codemorphs","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vscodeshift%2Freact-codemorphs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vscodeshift%2Freact-codemorphs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vscodeshift%2Freact-codemorphs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vscodeshift%2Freact-codemorphs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vscodeshift","download_url":"https://codeload.github.com/vscodeshift/react-codemorphs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271492,"owners_count":20911586,"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":["codemods","jscodeshift","react","refactoring","vscode"],"created_at":"2024-12-18T05:30:16.127Z","updated_at":"2025-04-05T00:43:26.279Z","avatar_url":"https://github.com/vscodeshift.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Codemorphs\n\n[![CircleCI](https://circleci.com/gh/vscodeshift/react-codemorphs.svg?style=svg)](https://circleci.com/gh/vscodeshift/react-codemorphs)\n[![Coverage Status](https://codecov.io/gh/vscodeshift/react-codemorphs/branch/master/graph/badge.svg)](https://codecov.io/gh/vscodeshift/react-codemorphs)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/vscodeshift.react-codemorphs)](https://marketplace.visualstudio.com/items?itemName=vscodeshift.react-codemorphs)\n\nCodemod commands for everyday work with React. All commands support Flow, TypeScript, and plain JS.\n\n# Wrap with JSX Element\n\nAdds a parent JSX Element around the selected JSX node(s) or the node that contains the cursor.\n\n## Example\n\n### Before\n\n```tsx\nconst Foo = () =\u003e (\n  \u003cdiv\u003e\n    // selection start\n    {foo}\n    {bar}\n    \u003cspan /\u003e\n    // selection end\n    {baz}\n  \u003c/div\u003e\n)\n```\n\n### After\n\n```tsx\nconst Foo = () =\u003e (\n  \u003cdiv\u003e\n    \u003cTest\u003e\n      {foo}\n      {bar}\n      \u003cspan /\u003e\n    \u003c/Test\u003e\n    {baz}\n  \u003c/div\u003e\n)\n```\n\n# Wrap with Child Function Element\n\nWraps the JSX Element that contains the cursor in a parent JSX Element with a child function\n(making the child function return the wrapped element).\n\n## Example\n\n### Before\n\n```tsx\nconst Foo = () =\u003e (\n  \u003cdiv\u003e\n    \u003cBar /\u003e\n  \u003c/div\u003e\n)\n```\n\nPosition cursor in `\u003cBar /\u003e` then run the command.\n\n### After\n\n```tsx\nconst Foo = () =\u003e (\n  \u003cdiv\u003e\n    \u003cTest\u003e{(): React.ReactNode =\u003e \u003cBar /\u003e}\u003c/Test\u003e\n  \u003c/div\u003e\n)\n```\n\n# `addProp`\n\nAdds the identifier under the cursor as a prop to the surrounding component.\nAdds a prop type declaration if possible, and binds the identifier via destructuring on `props`\nor replaces it with a reference to `props`/`this.props`.\n\n## Example\n\n### Before\n\n```tsx\nimport * as React from 'react'\n\ninterface Props {}\n\nconst Foo = (props: Props) =\u003e \u003cdiv\u003e{text}\u003c/div\u003e\n```\n\nPosition cursor in the middle of `text` and then run the command.\nThe command will prompt you what type to use for the property, enter `string` for example:\n\n### After (with formatting)\n\n```tsx\nimport * as React from 'react'\n\ninterface Props {\n  text: string\n}\n\nconst Foo = (props: Props) =\u003e \u003cdiv\u003e{props.text}\u003c/div\u003e\n```\n\n# Render Conditionally\n\nWraps the selected JSX in `{true \u0026\u0026 ...}`. If\nthere are multiple siblings selected, wraps in `{true \u0026\u0026 \u003cReact.Fragment\u003e...\u003c/React.Fragment\u003e}`.\n\nIf you want to wrap in a ternary conditional like Glean's\n\"Render Conditionally\" refactor, see `wrapWithTernaryConditional`.\n\n## Example\n\n### Before\n\n```tsx\nconst Foo = () =\u003e (\n  \u003cdiv\u003e\n    {foo} bar\n    \u003cspan /\u003e\n    {baz}\n  \u003c/div\u003e\n)\n```\n\nSelect from before `{foo}` to before `{baz}`, then run the command.\n\n### After (with formatting)\n\n```tsx\nconst Foo = () =\u003e (\n  \u003cdiv\u003e\n    {true \u0026\u0026 (\n      \u003cReact.Fragment\u003e\n        {foo} bar\n        \u003cspan /\u003e\n      \u003c/React.Fragment\u003e\n    )}\n    {baz}\n  \u003c/div\u003e\n)\n```\n\n# Wrap with Ternary Conditional\n\nWraps the selected JSX in `{true ? ... : null}`. If\nthere are multiple siblings selected, wraps in `{true ? \u003cReact.Fragment\u003e...\u003c/React.Fragment\u003e : null}`.\n\n## Example\n\n### Before\n\n```tsx\nconst Foo = () =\u003e (\n  \u003cdiv\u003e\n    {foo} bar\n    \u003cspan /\u003e\n    {baz}\n  \u003c/div\u003e\n)\n```\n\nSelect from before `{foo}` to before `{baz}`, then run the command.\n\n### After (with formatting)\n\n```tsx\nconst Foo = () =\u003e (\n  \u003cdiv\u003e\n    {true ? (\n      \u003cReact.Fragment\u003e\n        {foo} bar\n        \u003cspan /\u003e\n      \u003c/React.Fragment\u003e\n    ) : null}\n    {baz}\n  \u003c/div\u003e\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvscodeshift%2Freact-codemorphs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvscodeshift%2Freact-codemorphs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvscodeshift%2Freact-codemorphs/lists"}