React 16 + React router 4 + Redux + Webpack 4 + Babel 7 + SSR
See original GitHub issue💬 Questions and Help
Hello @neoziro
I try to make React Router 4 + React 16 + Redux + Loadable Components + Webpack 4 to work together but fail.
I start from your server side rendering example https://github.com/smooth-code/loadable-components/tree/master/examples/server-side-rendering.
In the following code from your example :
const nodeExtractor = new ChunkExtractor({ statsFile: nodeStats })
const { default: App } = nodeExtractor.requireEntrypoint()
const webExtractor = new ChunkExtractor({ statsFile: webStats })
const jsx = webExtractor.collectChunks(<App />)
const html = renderToString(jsx)
App is the same on client and on server side.
However, when using React Router + Redux, you need to wrap differently your App component depending you’re on client side or server side :
client
import { Router } from "react-router-dom";
import { Provider } from "react-redux";
const initialState = window.__INITIAL_STATE__;
const store = createStore(reducers, initialState)
<Provider store={store}>
<Router>
<App>
</Router>
</Provider>
server
import { StaticRouter } from "react-router";
import { Provider } from "react-redux";
const initialState = ...; // initial state is initialised from value from express req
const store = createStore(reducers, initialState)
<Provider store={store}>
<StaticRouter location={req.url}>
<App>
</StaticRouter>
</Provider>
In my case, the code from your example does not work :
const nodeExtractor = new ChunkExtractor({ statsFile: nodeStats })
const { default: App } = nodeExtractor.requireEntrypoint()
const webExtractor = new ChunkExtractor({ statsFile: webStats })
const jsx = webExtractor.collectChunks(<App />)
const html = renderToString(jsx)
I can’t figure out how to make them work together ?
Can you help me please ?
Best regards
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
React 16 with Webpack 4 and Babel 7 Part 2 - Medium
So now let us add react-router and the global state - Redux, on our react application. This is the continuation from my previous...
Read more >React v16.0 – React Blog
We're excited to announce the release of React v16.0! Among the changes are some long-standing feature requests, including fragments, ...
Read more >React Starter Projects | JavaScript Stuff
A simple and powerful React framework with minimal API and zero boilerplate. dependency. babel. redux. linter. router. tests. webpack 4.
Read more >I'm getting an about babel-preset-react not being found
I'm not quite sure if I'm missing a package that is necessary or have something misconfigured...? babeljs · webpack-4 · react-ssr · Share....
Read more >Complete Intro to React
A Complete Intro to React, as taught for FrontendMasters.com. ... Express, Redux, Webpack, Jest, Enzyme, Yarn, Prettier, ESLint, and React-Router.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can’t use ReactDOM.hydrate in [React 16 + React router 4 + Redux + Webpack 4 + Babel 7 + SSR + React-inl] project? When I changed render to hydrate, it logged warning : "Warning: Expected server HTML to contain a matching … "
Hi
I have finally made it.
Here is a repo https://github.com/lauterry/perfect-react-app which illustrate how loadable-components works with React 16 + React router 4 + Redux + Webpack 4 + Babel 7 + SSR + React-inl
@neoziro Do you mind having a look at my repo and tell me if you see anything weird or incorrect or anything I can make better please ?
Thx