I want to use nextjs
in my new project with redux
and thunk
also. I wondering how to implement all packages correctly.
In my previous projects pages has HOC
components like:
import {connect} from 'react-redux';
import Page from './about';
import {fetchUsers} from '../../actions/user';
const mapStateToProps = (state) => {
const {users} = state;
return users;
};
const mapDispatchToProps = (dispatch) => {
return {
fetchUsers: () => dispatch(fetchUsers())
};
};
export default connect(mapStateToProps, mapDispatchToProps)(Page);
And method to fetch users I implemented in componentDidMount
How to implement the same logic for nexjs
?
What have I do?
- Implemented store (base on next-redux-wrapper in _app.js)
- Created
HOC
component (like below) withmapStateToProps
andmapDispatchToProps
Currently I thinking about use somehow this.props.fetchUsers
method into getInitialProps
- documentation say that this method should be used to fetch data before render site.
Please help me with correctly redux
implementation for nextjs