Skip to content

Instantly share code, notes, and snippets.

@adrianolsk
Created July 22, 2019 18:28
Show Gist options
  • Save adrianolsk/20157371958a8b701882c750afbd9b87 to your computer and use it in GitHub Desktop.
Save adrianolsk/20157371958a8b701882c750afbd9b87 to your computer and use it in GitHub Desktop.
// 1
import { peopleReducer as peopleState } from './reducers/peopleReducer.ts';
import { combineReducers } from 'redux';
export const rootReducer = combineReducers({
peopleState,
});
export type AppState = ReturnType<typeof rootReducer>;
// 2
type AppStateProps = ReturnType<typeof mapStateToProps>;
type AppDispatchProps = ReturnType<typeof mapDispatchToProps>;
type AppProps = AppStateProps & AppDispatchProps;
const App = (props: AppProps) => (
<div>
{ /* ... */ }
</div>
)
const mapStateToProps = (state: AppState) => ({
people: state.peopleState.people,
peopleLoading: state.peopleState.loading,
personPosting: state.peopleState.posting,
});
const mapDispatchToProps = (dispatch: ThunkDispatch<any, any, AnyAction>) => {
return {
getPeople: () => dispatch(getPeopleActionCreator()),
postPerson: (person: IPostPerson) => dispatch(postPersonActionCreator(person)),
};
};
export default connect(mapStateToProps, mapDispatchToProps)(App);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment