サーバサイドだけでReact使う / React as Template Engine

F7dd7b43a0cc6c063f7d98ba23a1d359?s=47 久保田光則
June 05, 2019
240

サーバサイドだけでReact使う / React as Template Engine

React勉強会@福岡 vol.2での発表資料

F7dd7b43a0cc6c063f7d98ba23a1d359?s=128

久保田光則

June 05, 2019
Tweet

Transcript

  1. 7.

    // ୯ʹnodeͰಈ͔͢৔߹ const React = require('react'); const {renderToStaticMarkup} = require('react-dom/server');

    function HelloWorld() { return <div>Hello World!!!!</div>; } console.log(renderToStaticMarkup(<HelloWorld />));
  2. 8.

    // expressͱ૊Έ߹Θͤͯ࢖͏৔߹ const express = require('express'); const React = require('react');

    const {renderToStaticMarkup} = require('react-dom/server'); function HelloWorld() { return <div>Hello World!!!!</div>; } const app = express(); app.get('/', (req, res) => { res.send(renderToStaticMarkup(<HelloWorld />)); }); app.listen(3000);