Skip to content

osamu38/react-ssr-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

03ae982 · Jul 10, 2020
Sep 17, 2018
Jul 10, 2020
Jul 10, 2020
Jul 6, 2020
Jul 6, 2020
Jul 8, 2020
Jul 6, 2020
May 14, 2018
May 14, 2018
Jul 8, 2020
Aug 6, 2018
Jul 10, 2020
Oct 3, 2019
Sep 7, 2018
May 23, 2018
May 23, 2018
Jul 8, 2020

Repository files navigation

react-ssr-starter

All have been introduced React environment.

Features

Install

$ git clone https://github.com/osamu38/react-ssr-starter.git
$ cd react-ssr-starter
$ npm i

Run

$ npm run dev

Go to http://localhost:2525/.

Build

$ npm run build
$ npm run build:client (Only build client)
$ npm run build:server (Only build server)

Build and analyze

$ npm run build:analyze
$ npm run build:client:analyze
$ npm run build:server:analyze

Run for production

npm start

Go to http://localhost:2525/.

Adding pages

Basically page component is implemented using Functional Component.

pages/home/index.js

import React from 'react';
import { Helmet } from 'react-helmet-async';
import Title from 'components/Title';
import SubTitle from 'components/SubTitle';
import UserList from 'components/UserList';
import { fetchUsers } from 'actions/user';

const HomePage = (props) => {
  const {
    state: {
      user: { userList },
    },
  } = props;

  return (
    <>
      <Helmet title="Home" />
      <Title>Home Page</Title>
      <SubTitle>User List</SubTitle>
      <UserList userList={userList} />
    </>
  );
};

HomePage.loadData = async (ctx) => {
  const {
    dispatch,
    state: {
      user: { userList },
    },
  } = ctx;

  if (!userList.length) {
    return dispatch(fetchUsers());
  }
  return Promise.resolve();
};

export default HomePage;