React-Redux inspired global state library using React's new Context API and HOCs
import { provide } from 'context-hoc';
// ...
const initialState = { message: '' };
const reducer = (state, action) => {
switch (action.type) {
case 'greeting':
return { message: action.payload };
default:
return state;
}
};
export default provide(initialState, reducer)(App);
import { consume } from 'context-hoc';
// ...
const mapStateToProps = (state, ownProps) => {
return {
excitedMessage: `${state.message}!`,
};
};
const mapDispatchToProps = (dispatch, ownProps) => ({
greet: payload => dispatch({ type: 'greeting', payload }),
});
export default consume(mapStateToProps, mapDispatchToProps)(Child);