@25sprout/react-starter
Version:
25sprout web starter with React
22 lines (14 loc) • 644 B
JavaScript
import { bindActionCreators } from 'redux';
import { useSelector, useDispatch } from 'react-redux';
const defaultSelector = state => state;
export const useRedux = (originSelector, actions, options = {}) => {
const selector = typeof originSelector !== 'function' ? defaultSelector : originSelector;
const state = useSelector(selector, options.shouldHooksUpdate);
const dispatch = useDispatch();
if (typeof actions === 'undefined' || actions === null) {
return [state, dispatch];
}
const boundActions =
typeof actions === 'function' ? actions(dispatch) : bindActionCreators(actions, dispatch);
return [state, boundActions];
};