npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-react-view

v3.0.0

Published

server side react render for koa

Downloads

23

Readme

koa-react-view

NPM version build status Test coverage David deps node version

A Koa view engine which renders React components on server.

Installation

$ npm install koa-react-view

Usage

var react = require('koa-react-view');
var path = require('path');
var koa = require('koa');

var app = koa();

var viewpath = path.join(__dirname, 'views');
var assetspath = path.join(__dirname, 'public');

react(app, {
  views: viewpath
});

app.use(function* () {
  this.render(home, {foo: 'bar'});
});

This module no longer includes the Babel runtime, as that prevented developers from using the runtime on the server outside of the scope of this module. Additionally, Babel recommends that the polyfill is only included by the parent app to avoid these conflicts. If you'd like to use JSX, ES6, or other features that require transpiling, you can include Babel in your project directly. See example.

Options

option | values | default -------|--------|-------- doctype | any string that can be used as a doctype, this will be prepended to your document | "<!DOCTYPE html>" beautify | true: beautify markup before outputting (note, this can affect rendering due to additional whitespace) | false views | the root directory of view files | path.join(__dirname, 'views') extname | the default view file's extname | jsx writeResp | true: writes the body response automatically | true cache | true: cache all the view files | process.env.NODE_ENV === 'production' internals | true: include React internals in output | false

renderToString vs renderToStaticMarkup

React provides two ways to render components server-side:

  • ReactDOMServer.renderToStaticMarkup strips out all the React internals, reducing the size of the output. Best for static sites.

  • 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.

By 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.

ctx.state

koa-react-view support ctx.state in koa.

example

License

MIT