Add useGetState hook
This commit is contained in:
parent
a19b1e83a9
commit
8547aeb517
|
@ -5,6 +5,7 @@ export { useAppSelector } from './useAppSelector';
|
||||||
export { useClickOutside } from './useClickOutside';
|
export { useClickOutside } from './useClickOutside';
|
||||||
export { useCompose } from './useCompose';
|
export { useCompose } from './useCompose';
|
||||||
export { useDebounce } from './useDebounce';
|
export { useDebounce } from './useDebounce';
|
||||||
|
export { useGetState } from './useGetState';
|
||||||
export { useGroup, useGroups } from './useGroups';
|
export { useGroup, useGroups } from './useGroups';
|
||||||
export { useGroupsPath } from './useGroupsPath';
|
export { useGroupsPath } from './useGroupsPath';
|
||||||
export { useDimensions } from './useDimensions';
|
export { useDimensions } from './useDimensions';
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
import api from 'soapbox/api';
|
import api from 'soapbox/api';
|
||||||
|
|
||||||
import { useAppDispatch } from './useAppDispatch';
|
import { useGetState } from './useGetState';
|
||||||
|
|
||||||
/** Use stateful Axios client with auth from Redux. */
|
/** Use stateful Axios client with auth from Redux. */
|
||||||
export const useApi = () => {
|
export const useApi = () => {
|
||||||
const dispatch = useAppDispatch();
|
const getState = useGetState();
|
||||||
|
return api(getState);
|
||||||
return dispatch((_dispatch, getState) => {
|
|
||||||
return api(getState);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { useAppDispatch } from './useAppDispatch';
|
||||||
|
|
||||||
|
import type { RootState } from 'soapbox/store';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a `getState()` function to hooks.
|
||||||
|
* You should prefer `useAppSelector` when possible.
|
||||||
|
*/
|
||||||
|
function useGetState() {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
return () => dispatch((_, getState: () => RootState) => getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
export { useGetState };
|
Loading…
Reference in New Issue