add Selector functionality

This commit is contained in:
Alfred Melch 2020-02-01 17:21:08 +01:00
parent 7434b1e17e
commit ccd684fef0

View File

@ -26,7 +26,8 @@ export const createStore = options => {
return React.createElement(context.Provider, { value: store }, children)
}
const useStore = () => useContext(context)
return { Provider, Consumer: context.Consumer, useStore }
const useSelector = selector => selector(useContext(context)[0])
return { Provider, Consumer: context.Consumer, useStore, useSelector }
}
/** Turn a reducer definition object to a function