MCPcopy
hub / github.com/reduxjs/redux / handleRender

Function handleRender

examples/universal/server/server.js:27–53  ·  view source on GitHub ↗
(req, res)

Source from the content-addressed store, hash-verified

25app.use(webpackHotMiddleware(compiler))
26
27const handleRender = (req, res) => {
28 // Query our mock API asynchronously
29 fetchCounter(apiResult => {
30 // Read the counter from the request, if provided
31 const params = qs.parse(req.query)
32 const counter = parseInt(params.counter, 10) || apiResult || 0
33
34 // Compile an initial state
35 const preloadedState = { counter }
36
37 // Create a new Redux store instance
38 const store = configureStore(preloadedState)
39
40 // Render the component to a string
41 const html = renderToString(
42 <Provider store={store}>
43 <App />
44 </Provider>
45 )
46
47 // Grab the initial state from our Redux store
48 const finalState = store.getState()
49
50 // Send the rendered page back to the client
51 res.send(renderFullPage(html, finalState))
52 })
53}
54
55// This is fired every time the server side receives a request
56app.use(handleRender)

Callers

nothing calls this directly

Calls 4

fetchCounterFunction · 0.90
renderFullPageFunction · 0.85
getStateMethod · 0.65
configureStoreFunction · 0.50

Tested by

no test coverage detected