You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

gatsby-plugin-react-redux

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-plugin-react-redux

Gatsby plugin for React-Redux with built-in server-side rendering support

1.0.6
Source
npmnpm
Version published
Weekly downloads
945
41.26%
Maintainers
1
Weekly downloads
 
Created
Source

gatsby-plugin-react-redux

A Gatsby plugin for react-redux with built-in server-side rendering support.

Install

npm install --save gatsby-plugin-react-redux

What it does

  • Wraps your app with redux Provider on both client and server
  • Securely serializes store state with serialize-javascript on the server and passes it to your createStore function on the client

How to use

1. Create module that exports a function which:

  • accepts a single argument preloadedState
  • creates redux store passing preloadedState as 2nd argument
  • returns created store

Example:

./src/state/createStore.js

import { createStore } from 'redux';
import reducer from './reducer';

// For ES5 use `module.exports`
export default preloadedState => {
  return createStore(reducer, preloadedState);
};

2. Edit ./gatsby-config.js

module.exports = {
 plugins: [
   {
     resolve: `gatsby-plugin-react-redux`,
     options: {
       // [required] - path to module you created in step 1
       pathToCreateStoreModule: './src/state/createStore',
       // [optional] - options passed to `serialize-javascript`
       // info: https://github.com/yahoo/serialize-javascript#options
       // defaults:
       serialize: {
         space: 0,
         isJSON: true,
         unsafe: false,
       },
     },
   },
 ],
};

License

MIT

Keywords

gatsby

FAQs

Package last updated on 07 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts