@25sprout/react-starter
Version:
25sprout web starter with React
27 lines (20 loc) • 610 B
JavaScript
import { createAction, handleActions } from 'redux-actions';
import { createContext, useContext } from 'react';
import history from 'store/history';
export const routeChange = createAction('ROUTE_LOCATION_CHANGE', location => location);
export const defaultState = { ...history.location };
export const reducer = {
routing: handleActions(
{
ROUTE_LOCATION_CHANGE: (state, action) => ({
...state,
...action.payload,
}),
},
defaultState,
),
};
export const HistoryContext = createContext({
location: { pathname: '/' },
});
export const useHistory = () => useContext(HistoryContext);