{"id":13671474,"url":"https://github.com/koajs/react-view","last_synced_at":"2025-04-06T03:06:42.487Z","repository":{"id":33381109,"uuid":"37026067","full_name":"koajs/react-view","owner":"koajs","description":"A Koa view engine which renders React components on server","archived":false,"fork":false,"pushed_at":"2022-01-23T16:04:51.000Z","size":194,"stargazers_count":259,"open_issues_count":7,"forks_count":30,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-10-29T15:32:18.887Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koajs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-07T17:49:48.000Z","updated_at":"2024-07-19T23:56:32.000Z","dependencies_parsed_at":"2022-09-06T23:30:17.985Z","dependency_job_id":null,"html_url":"https://github.com/koajs/react-view","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Freact-view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Freact-view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Freact-view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Freact-view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/react-view/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247427006,"owners_count":20937201,"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":[],"created_at":"2024-08-02T09:01:10.518Z","updated_at":"2025-04-06T03:06:42.462Z","avatar_url":"https://github.com/koajs.png","language":"JavaScript","funding_links":[],"categories":["Middleware","仓库","JavaScript"],"sub_categories":["中间件"],"readme":"koa-react-view\n---------------\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![David deps][david-image]][david-url]\n[![node version][node-image]][node-url]\n\n[npm-image]: https://img.shields.io/npm/v/koa-react-view.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/koa-react-view\n[travis-image]: https://img.shields.io/travis/koajs/react-view.svg?style=flat-square\n[travis-url]: https://travis-ci.org/koajs/react-view\n[coveralls-image]: https://img.shields.io/coveralls/koajs/react-view.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/koajs/react-view?branch=master\n[david-image]: https://img.shields.io/david/koajs/react-view.svg?style=flat-square\n[david-url]: https://david-dm.org/koajs/react-view\n[node-image]: https://img.shields.io/badge/node.js-%3E=_0.12-green.svg?style=flat-square\n[node-url]: http://nodejs.org/download/\n\nA Koa view engine which renders React components on server.\n\n## Installation\n\n```bash\n$ npm install koa-react-view\n```\n\n## Usage\n\n```js\nvar react = require('koa-react-view');\nvar path = require('path');\nvar koa = require('koa');\n\nvar app = koa();\n\nvar viewpath = path.join(__dirname, 'views');\nvar assetspath = path.join(__dirname, 'public');\n\nreact(app, {\n  views: viewpath\n});\n\napp.use(function* () {\n  this.render(home, {foo: 'bar'});\n});\n\n```\n\nThis module no longer includes the [Babel] runtime, as that prevented developers\nfrom using the runtime on the server outside of the scope of this module. Additionally,\nBabel recommends that the polyfill is only included by the parent app to avoid these\nconflicts. If you'd like to use JSX, ES6, or other features that require transpiling,\nyou can include Babel in your project directly. See [example].\n\n### Options\n\noption | values | default\n-------|--------|--------\n`doctype` | any string that can be used as [a doctype](http://en.wikipedia.org/wiki/Document_type_declaration), this will be prepended to your document | `\"\u003c!DOCTYPE html\u003e\"`\n`beautify` | `true`: beautify markup before outputting (note, this can affect rendering due to additional whitespace) | `false`\n`views` | the root directory of view files | `path.join(__dirname, 'views')`\n`extname` | the default view file's extname | `jsx`\n`writeResp` | `true`: writes the body response automatically | `true`\n`cache` | `true`: cache all the view files | `process.env.NODE_ENV === 'production'`\n`internals` | `true`: include React internals in output | `false`\n\n### renderToString vs renderToStaticMarkup\n\nReact provides two ways to render components server-side:\n\n- [ReactDOMServer.renderToStaticMarkup](https://facebook.github.io/react/docs/top-level-api.html#reactdomserver.rendertostaticmarkup) strips out all the React internals, reducing the size of the output. Best for static sites.\n\n- [ReactDOMServer.renderToString](https://facebook.github.io/react/docs/top-level-api.html#reactdomserver.rendertostring) maintains React internals, allowing for client-side React to process the rendered markup very speedily. Best for an initial server-side rendering of a client-side application.\n\nBy default, the `ReactDOMServer.renderToStaticMarkup` method will be used. It is possible to use `ReactDOMServer.renderToString` instead (and maintain the React internals) by setting the `internals` option to `true`, or by setting the third parameter of `this.render` to `true` on a case-by-case basis.\n\n### `ctx.state`\n\n`koa-react-view` support [ctx.state](https://github.com/koajs/koa/blob/master/docs/api/context.md#ctxstate) in koa.\n\n### [example](example)\n\n### License\n\nMIT\n\n[Babel]: http://babeljs.io/\n[example]: https://github.com/koajs/react-view/blob/master/example/app.js#L25\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Freact-view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Freact-view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Freact-view/lists"}