some useful react function helpers :)
npm install react-function-helpers``
type OwnProps = { index: number, listData: SingleEstimateStop }
const mapStateToProps: MapStateToProps
}> = (state, ownProps) => ({
isSelected: ownProps.index === state.selectedRouteStopIndex
});
`
``
const mapDispatchToProps: MapDispatchToProps
}> = (dispatch) => ({
listClickFn: (routeStopId: number) => {
dispatch(setRouteStopId(routeStopId));
}
});
``
const ComponentWithCtx = connectCtx(ContextStore)(mapStateToProps?, mapDispatchToProps?)(Component)
`
interface CollinearRoutesState {
selectedRouteId: SelectedRouteId
stopSearchFromTo: StopSearchFromTo
}
const reducers = combineReducers
selectedRouteId: selectedRouteId_reducer,
stopSearchFromTo: stopSearchFromTo_reducer,
});
`
---
`
const initState = {//context state...}
const reducers = {//reducers}
const ContextValueFn = createContextValueFn(initState, reducers);
`
``
const initState = {//context state...}
const ContextStore = createContextStore(initState, dispatch?)
`
export const ContextWrapper = ContextWrapperFn(ContextValueFn, ContextStore);
//wrap a component which consume context
``