Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

久保田光則
June 05, 2019
710

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

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

久保田光則

June 05, 2019
Tweet

More Decks by 久保田光則

Transcript

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

    function HelloWorld() { return <div>Hello World!!!!</div>; } console.log(renderToStaticMarkup(<HelloWorld />));
  2. // 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);