• Stars
    star
    242
  • Rank 167,048 (Top 4 %)
  • Language
    JavaScript
  • Created about 9 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A universal react starter, with routing, meta, title, and data features

Universal React

This boilerplate aims at solving the MVP (Minimal Viable Product) of a universal app while trying to keep the base unopinionated elsewhere and simple to read and extend.

Universal React on NPM Dependency Status

Features

  • Universal routing react-router
  • Redux
  • Hot reloading
  • Title, meta, css, and scripts overridable by each component react-helmet
  • Universal data fetching/rehydration on the client cross-fetch
  • No other templating engines - React from root down
  • 404 and redirect handling
  • Shared app config
  • Webpack and Babel

Since there are so many opinions on how to use css (vanilla, sass, less, react css modules etc) I've left it up to you.

##ย Install & run

npm i && npm start

Go to http://localhost:3000/.

Build

npm run build

This will create a dist/ folder with a app.min.js which will be used on any environment which isn't undefined (i.e. not local).

npm run start-prod

This will build and then run your app with environment set to production, so that app.min.js and config/production.js are used.

Adding routes

Add your routes in Routes.js.

<Route path="users" component={Users} />

Title and Meta

The parent App.js defines the base title and meta in a Helmet component. Any sub-component can override/add properties (even adding scripts and css). See the react-helmet docs for more info.

Config

You can store app settings under app/config/. A file matching process.env.NODE_ENV will be loaded, for example app/config/production.js. If process.env.NODE_ENV is undefined it will fallback to app/config/default.js. You can access the correct config with:

import config from './config';

Data fetching and client hydration

Read the Redux guide if you are new to redux. Write Redux actions and stores as normal, and if the action creator is asynchronous then it should return a Promise (or a Promise.all) in the inner function.

You should write dispatches for actions that must be called for the container to be ready:

static readyOnActions(dispatch, params) {
  return Promise.all([
    dispatch(UserActions.fetchUserIfNeeded(params.id))
  ]);
}

You should also invoke the actions in componentDidMount. This ensures that if the component is reached on the client, then the same actions will be invoked. It's up to the action to figure out if fetches for data need to be made or not:

componentDidMount() {
  User.readyOnActions(this.props.dispatch, this.props.params);
}

More Repositories

1

react-image-crop

A responsive image cropping tool for React
TypeScript
3,869
star
2

keshi

A better in-memory cache for Node and the browser
JavaScript
75
star
3

ccy-icons

A set of 330+ currency icons (fiat and crypto) as SVGs and React components
SCSS
56
star
4

detourxs

A x86/64 library for detouring functions on Windows OS
C++
43
star
5

SecurePad

SecurePad - A Notepad++ plugin for securely encrypting data
C
38
star
6

extnd

Multiple inheritance and _super in javascript
JavaScript
14
star
7

lightgrid

A fast, lightweight, full-featured Datagrid for React
TypeScript
12
star
8

aneto

A simple zero cost CSS-in-JS solution for React
TypeScript
9
star
9

react-js2css-theme

Expose theme objects but use CSS Variables internally
JavaScript
7
star
10

tlsopenglhook

Stealthy TLS OpenGL hooking
C++
7
star
11

osx-menubar-calendar

A simple date/time menubar which has a calendar popup
Swift
6
star
12

bun-css-modules

Import CSS Modules into Bun for server rendered html/components
TypeScript
4
star
13

go-orderbook

A market+limit orderbook in Go
Go
3
star
14

ion-tray

A Web Component which enables you to have central content with a left and right tray which can 'push' into view
3
star
15

mdx-infinite-render-loop

JavaScript
2
star
16

js-orderbook

A Javascript (TS) implementation of an orderbook
TypeScript
2
star
17

mockster

A library for mocking fetch responses.
JavaScript
2
star
18

ts-loader-declaration-bug

ts-loader declarations stop generating on style changes bug
JavaScript
2
star
19

shape-test

JavaScript
1
star
20

chrome-ios-autofill-change-bug

A demonstration for an iOS Chrome autofill bug
HTML
1
star
21

babel-plugin-source-code

A babel plugin which allows you to render Prism syntax highlighted code snippets of files with 0 runtime cost
JavaScript
1
star
22

i18n-simple

A simple, fast, opinionated but flexible string translator for NodeJS
JavaScript
1
star
23

debounce.lodash

Typescript debounce and throttle by Lodash
TypeScript
1
star