{"id":18979674,"url":"https://github.com/nihgwu/react-runner","last_synced_at":"2025-04-08T08:12:21.615Z","repository":{"id":38630652,"uuid":"190829352","full_name":"nihgwu/react-runner","owner":"nihgwu","description":"Run your React code on the go","archived":false,"fork":false,"pushed_at":"2024-06-05T18:56:09.000Z","size":4946,"stargazers_count":481,"open_issues_count":14,"forks_count":25,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T05:32:26.103Z","etag":null,"topics":["live","playground","react"],"latest_commit_sha":null,"homepage":"https://react-runner.vercel.app","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/nihgwu.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":"2019-06-08T00:47:20.000Z","updated_at":"2025-03-30T21:23:32.000Z","dependencies_parsed_at":"2024-06-18T13:59:27.519Z","dependency_job_id":"653f0923-d69e-4473-b51b-215549274002","html_url":"https://github.com/nihgwu/react-runner","commit_stats":{"total_commits":148,"total_committers":3,"mean_commits":"49.333333333333336","dds":"0.013513513513513487","last_synced_commit":"974ebc932db7b7c7d59f1b50a79aed705efbf75a"},"previous_names":[],"tags_count":77,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nihgwu%2Freact-runner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nihgwu%2Freact-runner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nihgwu%2Freact-runner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nihgwu%2Freact-runner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nihgwu","download_url":"https://codeload.github.com/nihgwu/react-runner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247801169,"owners_count":20998339,"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":["live","playground","react"],"created_at":"2024-11-08T15:44:24.100Z","updated_at":"2025-04-08T08:12:21.592Z","avatar_url":"https://github.com/nihgwu.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# React Runner\n\nRun your React code on the go [https://react-runner.vercel.app](https://react-runner.vercel.app)\n\n## Features\n\n- Inline element\n- Function component\n- Class component, **with class fields support**\n- Composing components with `render` or `export default`\n- Server Side Rendering\n- `import` statement\n- [Multi files](https://react-runner.vercel.app/#multi-files)\n- Typescript\n\nWith React Runner, you can write your live code in the real world way, check out Hacker News [in react-runner](https://react-runner.vercel.app/#hacker-news) vs [in real world](https://react-runner.vercel.app/examples/hacker-news), with the same code\n\nYou can even build your own async runner to support dynamic imports, try [Play React](https://play-react.vercel.app)\n\n## Install\n\n```bash\n# Yarn\nyarn add react-runner\n\n# NPM\nnpm install --save react-runner\n```\n\n## Options\n\n- **code** `string`, _required_ the code to be ran\n- **scope** `object` globals that could be used in `code`\n\n## Usage\n\n```jsx\nimport { Runner } from 'react-runner'\n\nconst element = \u003cRunner code={code} scope={scope} onRendered={handleRendered} /\u003e\n```\n\nor use hook `useRunner` with cache support\n\n```jsx\nimport { useRunner } from 'react-runner'\n\nconst { element, error } = useRunner({ code, scope })\n```\n\n### `import` statement and multi files\n\n```js\nimport { importCode } from 'react-runner'\nimport * as YourPkg from 'your-pkg'\n\nconst baseScope = {\n  /* base globals */\n}\n\nconst scope = {\n  ...baseScope,\n  // scope used by import statement\n  import: {\n    constants: { A: 'a' },\n    'your-pkg': YourPkg,\n    './local-file': importCode(localFileContent, baseScope),\n  },\n}\n```\n\nthen in your live code you can import them\n\n```js\nimport { A } from 'constants'\nimport Foo, { Bar } from 'your-pkg'\nimport What, { Ever } from './local-file'\n\nexport default function Demo() {\n  /* render */\n}\n```\n\n## Browser support\n\n```\n\"browserslist\": [\n  \"Chrome \u003e 61\",\n  \"Edge \u003e 16\",\n  \"Firefox \u003e 60\",\n  \"Safari \u003e 10.1\"\n]\n```\n\n## Resources\n\n- [Play React](https://play-react.vercel.app/)\n- [CodeMirror for React Runner](https://react-runner-codemirror.vercel.app/)\n- [Storybook Addon](https://storybook.js.org/addons/storybook-addon-react-runner/)\n\n## react-live-runner\n\n`react-runner` is inspired by [react-live](https://github.com/FormidableLabs/react-live) heavily,\nI love it, but I love arrow functions for event handlers instead of bind them manually as well as other modern features,\nand I don't want to change my code to be compliant with restrictions, so I created this project,\nuse [Sucrase](https://github.com/alangpierce/sucrase) instead of [Bublé](https://github.com/bublejs/buble) to transpile the code.\n\nIf you are using `react-live` in your project and want a smooth transition, `react-live-runner` is there for you which provide the identical way to play with, and `react-live-runner` re-exports `react-runner` so you can use everything in `react-runner` by importing `react-live-runner`\n\n```jsx\nimport {\n  LiveProvider,\n  LiveEditor,\n  LiveError,\n  LivePreview,\n} from 'react-live-runner'\n\n...\n\u003cLiveProvider code={code} scope={scope}\u003e\n  \u003cLiveEditor /\u003e\n  \u003cLivePreview /\u003e\n  \u003cLiveError /\u003e\n\u003c/LiveProvider\u003e\n...\n```\n\nor hooks for better custom rendering\n\n```jsx\nimport { useLiveRunner, CodeEditor } from 'react-live-runner'\n\nconst { element, error, code, onChange } = useLiveRunner({\n  initialCode,\n  scope,\n  transformCode,\n})\n\n...\n\u003c\u003e\n  \u003cCodeEditor value={code} onChange={onChange}\u003e\n  \u003cdiv\u003e{element}\u003c/div\u003e\n  {error \u0026\u0026 \u003cpre\u003e{error}\u003c/pre\u003e}\n\u003c/\u003e\n...\n```\n\nor use `react-runner` directly\n\n```jsx\nimport { useState, useEffect } from 'react'\nimport { useRunner } from 'react-runner'\n\nconst [code, onChange] = useState(initialCode)\nconst { element, error } = useRunner({ code, scope })\n\nuseEffect(() =\u003e {\n  onChange(initialCode)\n}, [initialCode])\n\n...\n\u003c\u003e\n  \u003ctextarea value={code} onChange={event =\u003e onChange(event.target.value)}\u003e\n  \u003cdiv\u003e{element}\u003c/div\u003e\n  {error \u0026\u0026 \u003cpre\u003e{error}\u003c/pre\u003e}\n\u003c/\u003e\n...\n```\n\nCheck the real world usage here https://github.com/nihgwu/react-runner/blob/master/website/src/components/LiveRunner.tsx\n\n## License\n\nMIT © [Neo Nie](https://github.com/nihgwu)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnihgwu%2Freact-runner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnihgwu%2Freact-runner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnihgwu%2Freact-runner/lists"}