This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from 'react'; | |
export function useCounter(initial = 0) { | |
const [count, setCount] = useState(initial); | |
return [count, () => setCount(count + 1)]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const util = require('util'); | |
const crypto = require('crypto'); | |
const mkdrip = require('mkdirp'); | |
const fetch = require('node-fetch'); | |
const exists = util.promisify(fs.exists); | |
const readFile = util.promisify(fs.readFile); | |
module.exports = url => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const path = require("path"); | |
const router = require("express").Router(); | |
const { renderToNodeStream } = require("react-dom/server"); | |
const React = require("react"); | |
const ReactApp = require("../build/static/ssr/main").default; | |
console.log(ReactApp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require("path"); | |
const express = require("express"); | |
const serveStatic = require("serve-static"); | |
const reactApp = require("./react-app"); | |
const PORT = process.env.PORT || 3001; | |
const app = express(); | |
app.use(reactApp); | |
app.use(serveStatic(path.join(__dirname, "../build"))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "server-side-rendering-with-create-react-app", | |
"version": "0.1.0", | |
"private": true, | |
"dependencies": { | |
"react": "^16.1.1", | |
"react-dom": "^16.1.1", | |
"react-scripts": "1.0.17" | |
}, | |
"scripts": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const HtmlWebpackPlugin = require("html-webpack-plugin"); | |
const ManifestPlugin = require("webpack-manifest-plugin"); | |
const SWPrecacheWebpackPlugin = require("sw-precache-webpack-plugin"); | |
const config = require("react-scripts/config/webpack.config.prod"); | |
config.entry = "./src/index.ssr.js"; | |
config.output.filename = "static/ssr/[name].js"; | |
config.output.libraryTarget = "commonjs2"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install --save-dev eslint-config-prettier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
preact create default preact-workshop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install -g preact-cli |