forked from erikras/reactalicante2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPage.js
32 lines (28 loc) · 815 Bytes
/
Page.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React, { Component } from 'react'
import { Provider } from 'react-redux'
import initStore from './redux/initStore'
const page = WrappedComponent => {
class Page extends Component {
static async getInitialProps(context) {
const store = initStore()
const otherProps = WrappedComponent.getInitialProps
? await WrappedComponent.getInitialProps({ ...context, store })
: {}
return { ...otherProps, initialState: store.getState() }
}
constructor(props) {
super(props)
this.store = initStore(props.initialState)
}
render() {
const { initialState, ...rest } = this.props
return (
<Provider store={this.store}>
<WrappedComponent {...rest} />
</Provider>
)
}
}
return Page
}
export default page