Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use redux in multi page web site?

Tags:

reactjs

redux

I know how to use redux and react router for SPA. Wonder how to use redux in a more traditional multipage web applications with server side framework such as spring MVC, jsp, etc.

Can multiple pages share the same store? From the documentation for server side rendering, every page server sends needs a new store.

like image 371
jay.m Avatar asked May 08 '16 22:05

jay.m


People also ask

Can React be used for multi page?

The use cases for having multiple pages in a single React app are pretty simple. You can create a website, and easily classify different types of content on different pages. But, it should also be understood that the default implementation of React is made to use a single HTML file, and this is by design.

Can Redux have multiple stores?

As with several other questions, it is possible to create multiple distinct Redux stores in a page, but the intended pattern is to have only a single store. Having a single store enables using the Redux DevTools, makes persisting and rehydrating data simpler, and simplifies the subscription logic.

Does Redux share state between tabs?

The most popular one that's used with React is redux. Redux is not shared across multiple tabs.

How do you use Redux in The Great Gatsby?

In order to use Redux for custom state management in a Gatsby site, you'll need to hook into two of Gatsby's extension points: Wrap the root element in your Gatsby markup once using wrapRootElement , an API supporting both Gatsby's server rendering and browser JavaScript processes.


1 Answers

If you are using server side rendering (SSR) then the client will be created a new store on each render. A store is created with an initialState, so it is possible to hold state between routes using local/session storage or rendered into the head of a page and used during the store creation to maintain state between different applications.

like image 125
kwelch Avatar answered Nov 01 '22 17:11

kwelch