Skip to content

Instantly share code, notes, and snippets.

@jericbas
Created March 4, 2019 05:48
Show Gist options
  • Save jericbas/9200dfd34b6a32177b31d9cec1671c6e to your computer and use it in GitHub Desktop.
Save jericbas/9200dfd34b6a32177b31d9cec1671c6e to your computer and use it in GitHub Desktop.
Add Rematch with existing Redux implementation
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)
);
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