1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Support _app approach for upgraded Redux Wrapper (#4207)

* Support _app approach for upgraded Redux Wrapper

* Updated according to discussion

* Package.json versions
This commit is contained in:
Kirill Konshin 2018-05-08 05:57:41 -07:00 committed by Tim Neutkens
parent 4b95725e09
commit 76f5e979b3
5 changed files with 38 additions and 14 deletions

View file

@ -0,0 +1,2 @@
package-lock=false
save-exact=true

View file

@ -1,6 +1,6 @@
{
"name": "with-redux-wrapper",
"version": "1.0.0",
"version": "2.0.0",
"scripts": {
"dev": "next",
"build": "next build",
@ -8,13 +8,13 @@
},
"dependencies": {
"next": "latest",
"next-redux-wrapper": "^1.0.0",
"react": "^16.0.0",
"redux-devtools-extension": "^2.13.2",
"react-dom": "^16.0.0",
"react-redux": "^5.0.1",
"redux": "^3.6.0",
"redux-thunk": "^2.1.0"
"next-redux-wrapper": "latest",
"react": "16.3.2",
"react-dom": "16.3.2",
"react-redux": "5.0.7",
"redux": "4.0.0",
"redux-devtools-extension": "2.13.2",
"redux-thunk": "2.2.0"
},
"license": "ISC"
}

View file

@ -0,0 +1,22 @@
import React from 'react'
import {Provider} from 'react-redux'
import App, {Container} from 'next/app'
import withRedux from 'next-redux-wrapper'
import {initStore} from '../store'
export default withRedux(initStore)(class MyApp extends App {
static async getInitialProps ({Component, ctx}) {
return {
pageProps: (Component.getInitialProps ? await Component.getInitialProps(ctx) : {})
}
}
render () {
const {Component, pageProps, store} = this.props
return <Container>
<Provider store={store}>
<Component {...pageProps} />
</Provider>
</Container>
}
})

View file

@ -1,7 +1,7 @@
import React from 'react'
import { bindActionCreators } from 'redux'
import { initStore, startClock, addCount, serverRenderClock } from '../store'
import withRedux from 'next-redux-wrapper'
import { startClock, addCount, serverRenderClock } from '../store'
import { connect } from 'react-redux'
import Page from '../components/Page'
class Counter extends React.Component {
@ -34,4 +34,4 @@ const mapDispatchToProps = (dispatch) => {
}
}
export default withRedux(initStore, null, mapDispatchToProps)(Counter)
export default connect(null, mapDispatchToProps)(Counter)

View file

@ -1,7 +1,7 @@
import React from 'react'
import { bindActionCreators } from 'redux'
import { initStore, startClock, addCount, serverRenderClock } from '../store'
import withRedux from 'next-redux-wrapper'
import { startClock, addCount, serverRenderClock } from '../store'
import { connect } from 'react-redux'
import Page from '../components/Page'
class Counter extends React.Component {
@ -33,4 +33,4 @@ const mapDispatchToProps = (dispatch) => {
}
}
export default withRedux(initStore, null, mapDispatchToProps)(Counter)
export default connect(null, mapDispatchToProps)(Counter)