Add useGetState hook

develop^2
Alex Gleason 2023-03-13 17:45:35 -05:00
rodzic a19b1e83a9
commit 8547aeb517
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
3 zmienionych plików z 18 dodań i 6 usunięć

Wyświetl plik

@ -5,6 +5,7 @@ export { useAppSelector } from './useAppSelector';
export { useClickOutside } from './useClickOutside';
export { useCompose } from './useCompose';
export { useDebounce } from './useDebounce';
export { useGetState } from './useGetState';
export { useGroup, useGroups } from './useGroups';
export { useGroupsPath } from './useGroupsPath';
export { useDimensions } from './useDimensions';

Wyświetl plik

@ -1,12 +1,9 @@
import api from 'soapbox/api';
import { useAppDispatch } from './useAppDispatch';
import { useGetState } from './useGetState';
/** Use stateful Axios client with auth from Redux. */
export const useApi = () => {
const dispatch = useAppDispatch();
return dispatch((_dispatch, getState) => {
return api(getState);
});
const getState = useGetState();
return api(getState);
};

Wyświetl plik

@ -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 };