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 personSchema = yup.object({ | |
firstName: yup.string(), | |
nickName: yup.string().nullable(), | |
email: yup | |
.string() | |
.nullable() | |
.notRequired() | |
.email(), | |
birthDate: yup | |
.date() |
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 React from 'react'; | |
import ListGroup from 'react-bootstrap/ListGroup'; | |
import { url } from '../../shared/jokes-api'; | |
import Loading from '../../shared/loading'; | |
function reducer(state, action) { | |
switch (action.type) { | |
case 'loaded': | |
return { ...state, loading: false, jokes: action.payload }; |
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
export const moviesLoaded = movies => ({ | |
type: 'MOVIES-LOADED', | |
payload: movies, | |
}); | |
export const loadMovies = () => dispatch => | |
fetch('/movies.json') | |
.then(rsp => rsp.json()) | |
.then(movies => dispatch(moviesLoaded(movies))); |
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 { h, Component } from "preact"; | |
import { Link } from "preact-router"; | |
import style from "./style"; | |
export default class Movie extends Component { | |
element = null; | |
componentDidMount() { | |
this.props.observer.observe(this.element); | |
} |
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 { h, Component } from "preact"; | |
import { Router } from "preact-router"; | |
import Header from "./header"; | |
import Home from "../routes/home"; | |
import Movies from "../routes/movies"; | |
export default class App extends Component { | |
/** Gets fired when the route changes. | |
* @param {Object} event "change" event from [preact-router](http://git.io/preact-router) |
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"; |