Created
March 4, 2019 05:48
-
-
Save jericbas/9200dfd34b6a32177b31d9cec1671c6e to your computer and use it in GitHub Desktop.
Add Rematch with existing Redux implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { PureComponent } from 'react'; | |
import { connect } from 'react-redux'; | |
import { bindActionCreators } from 'redux'; | |
// actions | |
import getOldAction from 'actions/getOldAction'; | |
// component | |
const App = ({ getOldAction, newAction }) => { | |
return <div>App</div>; | |
}; | |
// state | |
const mapState = state => { | |
return { | |
org: state.org | |
}; | |
}; | |
const mapDispatch = dispatch => { | |
const actions = bindActionCreators( | |
{ | |
getOldAction | |
}, | |
dispatch | |
); | |
// action from rematch models | |
const { newAction } = dispatch; | |
const rematchActions = { | |
newAction | |
}; | |
return { | |
...actions, | |
...rematchActions | |
}; | |
}; | |
export default withRouter( | |
connect( | |
mapState, | |
mapDispatch | |
)(App) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import thunk from 'redux-thunk'; | |
import { init } from '@rematch/core'; | |
import { allReducers } from '../reducers/allReducers'; | |
import * as models from './models'; | |
const middlewares = [thunk]; | |
export default init({ | |
models, | |
redux: { | |
reducers: allReducers, | |
middlewares | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment