All Projects β†’ ikhsanalatsary β†’ next-react-boilerplate

ikhsanalatsary / next-react-boilerplate

Licence: other
πŸ”₯ NextJS with additional tech feature like react-boilerplate. Demo >>

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to next-react-boilerplate

create-react-redux-app
React boilerplate based on create-react-app
Stars: ✭ 49 (+145%)
Mutual labels:  immutable, redux-saga
Digag Pc React
digag pc website based on react.
Stars: ✭ 209 (+945%)
Mutual labels:  immutable, redux-saga
universal-routed-flux-demo
The code in this repo is intended for people who want to get started building universal flux applications, with modern and exciting technologies such as Reactjs, React Router and es6.
Stars: ✭ 31 (+55%)
Mutual labels:  immutable, immutablejs
react-redux-immutable-webpack-ssr-starter
React + React-Router 4 + Redux + ImmutableJS + Bootstrap + webpack 3 with with Server side rendering, Hot Reload and redux-devtools STARTER
Stars: ✭ 21 (+5%)
Mutual labels:  immutable, immutablejs
anonymous-web
πŸ’¬ A PreactJS powered progressive web (chat) application (Not active)
Stars: ✭ 28 (+40%)
Mutual labels:  pwapp, pwa-apps
isomorphic-react-redux-saga-ssr
Isomorphic, React, Redux, Saga, Server Side rendering, Hot Module Reloading, Ducks, Code Splitting
Stars: ✭ 19 (-5%)
Mutual labels:  immutable, redux-saga
React Native Immutable List View
πŸ“œ Drop-in replacement for ListView, FlatList, and VirtualizedList.
Stars: ✭ 206 (+930%)
Mutual labels:  immutable, immutablejs
Reactnativetemplate
Our example of simple application using ReactNative and some recommendations
Stars: ✭ 127 (+535%)
Mutual labels:  redux-saga, immutablejs
react-redux-nextjs-material-ui-pwa-starter
No description or website provided.
Stars: ✭ 33 (+65%)
Mutual labels:  next, pwa-boilerplate
extendable-immutable
Wrapper classes around Immutable.js that turn it inheritable
Stars: ✭ 58 (+190%)
Mutual labels:  immutable, immutablejs
Neos Ui
Neos CMS UI written in ReactJS with Immutable data structures.
Stars: ✭ 238 (+1090%)
Mutual labels:  redux-saga, immutablejs
abilitysheet
This app is ability sheet for beatmania iidx music of level 12.
Stars: ✭ 38 (+90%)
Mutual labels:  redux-saga, immutablejs
Eth Hot Wallet
Ethereum wallet with erc20 support / web wallet - built using react, web3, eth-lightwallet
Stars: ✭ 205 (+925%)
Mutual labels:  redux-saga, react-boilerplate
json-immutable
Immutable.JS structure-aware JSON serializer/deserializer
Stars: ✭ 23 (+15%)
Mutual labels:  immutable, immutablejs
React Native Feature Boilerplate
Feature based Architecture for developing Scalable React Native Apps πŸš€ using react, redux, sagas and hooks
Stars: ✭ 139 (+595%)
Mutual labels:  redux-saga, react-boilerplate
Typed Immutable
Immutable and structurally typed data
Stars: ✭ 263 (+1215%)
Mutual labels:  immutable, immutablejs
React Eyepetizer
reactη‰ˆγ€ŒEyepetizerγ€εΌ€ηœΌηŸ­θ§†ι’‘
Stars: ✭ 83 (+315%)
Mutual labels:  redux-saga, immutablejs
Molecule
βš›οΈ – :atom: – βš›οΈ Boilerplate for cross platform web/native react apps with electron.
Stars: ✭ 95 (+375%)
Mutual labels:  redux-saga, immutablejs
Collectable
High-performance immutable data structures for modern JavaScript and TypeScript applications. Functional interfaces, deep/composite operations API, mixed mutability API, TypeScript definitions, ES2015 module exports.
Stars: ✭ 233 (+1065%)
Mutual labels:  immutable, immutablejs
react-boilerplate-ssr
ssr react boilerplate
Stars: ✭ 25 (+25%)
Mutual labels:  redux-saga, react-boilerplate

Deploy to now

Base on redux-saga example

This example and documentation is based on the with-redux-saga example.

Tech Stack

  • redux
  • redux-saga
  • reselect
  • styled-components
  • ImmutableJS
  • react-helmet (pending)
  • i18n (pending)
  • offline-first
  • add to homescreen
  • eslint

Caution

  • This repo is still under development

PWA Report

PWA Report

How to use

git clone https://github.com/ikhsanalatsary/next-react-boilerplate.git
cd next-react-boilerplate

Install it and run:

npm install
npm run dev

Deploy it to the cloud with now (download)

now

The idea behind the example

Usually splitting your app state into pages feels natural, but sometimes you'll want to have global state for your app. This is an example using redux and redux-saga that works with universal rendering. This is just one way it can be done. If you have any suggestions or feedback please submit an issue or PR.

In the first example we are going to display a digital clock that updates every second. The first render is happening in the server and then the browser will take over. To illustrate this, the server rendered clock will have a different background color than the client one.

Our page is located at pages/index.js so it will map the route /. To get the initial data for rendering we are implementing the static method getInitialProps, initializing the redux store and dispatching the required actions until we are ready to return the initial state to be rendered. Since the component is wrapped with next-redux-wrapper, the component is automatically connected to Redux and wrapped with react-redux Provider, that allows us to access redux state immediately and send the store down to children components so they can access to the state when required.

For safety it is recommended to wrap all pages, no matter if they use Redux or not, so that you should not care about it anymore in all child components.

withRedux function accepts makeStore as first argument, all other arguments are internally passed to react-redux connect() function. makeStore function will receive initialState as one argument and should return a new instance of redux store each time when called, no memoization needed here. See the full example in the Next Redux Wrapper repository. And there's another package next-connect-redux available with similar features.

To pass the initial state from the server to the client we pass it as a prop called initialState so then it's available when the client takes over.

The trick here for supporting universal redux is to separate the cases for the client and the server. When we are on the server we want to create a new store every time, otherwise different users data will be mixed up. If we are in the client we want to use always the same store. That's what we accomplish in store.js

The clock, under components/clock.js, has access to the state using the connect function from react-redux. In this case Clock is a direct child from the page but it could be deep down the render tree.

The second example, under components/add-count.js, shows a simple add counter function with a class component implementing a common redux pattern of mapping state and props. Again, the first render is happening in the server and instead of starting the count at 0, it will dispatch an action in redux that starts the count at 1. This continues to highlight how each navigation triggers a server render first and then a client render second, when you navigate between pages.

What changed with next-redux-saga

The digital clock is updated every 800ms using the runClockSaga found in saga.js.

All pages are also being wrapped by next-redux-saga using a helper function from store.js:

import withRedux from 'next-redux-wrapper'
import nextReduxSaga from 'next-redux-saga'
import configureStore from './store'

export function withReduxSaga(BaseComponent) {
  return withRedux(configureStore)(nextReduxSaga(BaseComponent))
}

/**
 * Usage:
 *
 * class Page extends Component {
 *   // implementation
 * }
 *
 * export default withReduxSaga(Page)
 */

If you need to pass react-redux connect args to your page, you could use the following helper instead:

import withRedux from 'next-redux-wrapper'
import nextReduxSaga from 'next-redux-saga'
import configureStore from './store'

export function withReduxSaga(...connectArgs) {
  return BaseComponent => withRedux(configureStore, ...connectArgs)(nextReduxSaga(BaseComponent))
}

/**
 * Usage:
 *
 * class Page extends Component {
 *   // implementation
 * }
 *
 * export default withReduxSaga(state => state)(Page)
 */

Since redux-saga is like a separate thread in your application, we need to tell the server to END the running saga when all asynchronous actions are complete. This is automatically handled for you by wrapping your components in next-redux-saga. To illustrate this, pages/index.js loads placeholder JSON data on the server from https://jsonplaceholder.typicode.com/users. If you refresh pages/other.js, the placeholder JSON data will NOT be loaded on the server, however, the saga is running on the client. When you click Navigate, you will be taken to pages/index.js and the placeholder JSON data will be fetched from the client. The placeholder JSON data will only be fetched once from the client or the server.

After introducing redux-saga there was too much code in store.js. For simplicity and readability, the actions, reducers, sagas, and store creators have been split into seperate files: actions.js, reducer.js, saga.js, store.js

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].