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

think-react-render

v2.0.0

Published

react server side rendering for thinkjs 2.x

Downloads

11

Readme

Think-react-render

react server side rendering for thinkjs 2.x

NPM version Build Status Coverage Status

中文文档

Install

npm install think-react-render

How to use in thinkjs

open the middleware configuration file bootstrap/middleware.js, and add this content as follows for register middleware:

var reactRender = require('think-react-render');
think.middleware('react_render', reactRender);

edit the hook configuration file config/hook.js, edit the configuration properties, it can auto executes in each request and after the view parse.

module.exports = {
    'view_parse': ['append', 'react_render']
};

write React component in the view files, the middleware will capitalize the first letter of the tag identified as a React component and rendering in service side.

this is a part of JSX Syntax. doesn't support child component, so you can use it as a entrance.

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>React</title>
</head>
<body>
    <App name={appname}></App>
</body>
</html>

use this.assign() method in controller to assign the data to view files.

var Base = require('./base.js');

module.exports = think.controller(Base, {
    indexAction: function (self) {
        this.assign('appname', "think-react-render");
        return this.display();
    }
});

create your self component files in the view/component directory, such as the follows app.jsx:

var React = require('react');

module.exports = React.createClass({
    render: function () {
        return (
            <div id="app">{this.props.name}</div>
        );
    }
});

Here are the results rendered

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>React</title>
</head>
<body>
    <div id="app" data-reactid=".2cj2burx62o" data-react-checksum="-459794789">think-react-render</div>
</body>
</html>

Configuration

you can create config/react_render.js configuration file as follow:

module.exports = {
    jsx: true, // use jsx syntax? default is true
    extension: '.jsx', // The extension of component files, default is .jsx,
    root_path: 'component', // Component file path, the path relative for `view.root_path`, and this support absolute path.
    left_delimiter: '{', // The delimiter of component arrribute in view files, such as "name={appname}", this configuration doesn't work for react component file, you can change it when the default value conflict with view file syntax.
    right_delimiter: '}', // such as the above
    lower_name: true // is the component use lower case filename.
};

LICENSE

MIT