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",
|
"name": "with-redux-wrapper",
|
||||||
"version": "1.0.0",
|
"version": "2.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next",
|
"dev": "next",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
|
@ -8,13 +8,13 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"next": "latest",
|
"next": "latest",
|
||||||
"next-redux-wrapper": "^1.0.0",
|
"next-redux-wrapper": "latest",
|
||||||
"react": "^16.0.0",
|
"react": "16.3.2",
|
||||||
"redux-devtools-extension": "^2.13.2",
|
"react-dom": "16.3.2",
|
||||||
"react-dom": "^16.0.0",
|
"react-redux": "5.0.7",
|
||||||
"react-redux": "^5.0.1",
|
"redux": "4.0.0",
|
||||||
"redux": "^3.6.0",
|
"redux-devtools-extension": "2.13.2",
|
||||||
"redux-thunk": "^2.1.0"
|
"redux-thunk": "2.2.0"
|
||||||
},
|
},
|
||||||
"license": "ISC"
|
"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 React from 'react'
|
||||||
import { bindActionCreators } from 'redux'
|
import { bindActionCreators } from 'redux'
|
||||||
import { initStore, startClock, addCount, serverRenderClock } from '../store'
|
import { startClock, addCount, serverRenderClock } from '../store'
|
||||||
import withRedux from 'next-redux-wrapper'
|
import { connect } from 'react-redux'
|
||||||
import Page from '../components/Page'
|
import Page from '../components/Page'
|
||||||
|
|
||||||
class Counter extends React.Component {
|
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 React from 'react'
|
||||||
import { bindActionCreators } from 'redux'
|
import { bindActionCreators } from 'redux'
|
||||||
import { initStore, startClock, addCount, serverRenderClock } from '../store'
|
import { startClock, addCount, serverRenderClock } from '../store'
|
||||||
import withRedux from 'next-redux-wrapper'
|
import { connect } from 'react-redux'
|
||||||
import Page from '../components/Page'
|
import Page from '../components/Page'
|
||||||
|
|
||||||
class Counter extends React.Component {
|
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