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:
parent
4b95725e09
commit
76f5e979b3
2
examples/with-redux-wrapper/.npmrc
Normal file
2
examples/with-redux-wrapper/.npmrc
Normal file
|
@ -0,0 +1,2 @@
|
|||
package-lock=false
|
||||
save-exact=true
|
|
@ -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"
|
||||
}
|
||||
|
|
22
examples/with-redux-wrapper/pages/_app.js
Normal file
22
examples/with-redux-wrapper/pages/_app.js
Normal 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>
|
||||
}
|
||||
})
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue