soapbox/src/hooks/useOwnAccount.ts

21 wiersze
498 B
TypeScript
Czysty Zwykły widok Historia

2022-11-26 16:38:16 +00:00
import { useCallback } from 'react';
import { makeGetAccount } from 'soapbox/selectors';
import { useAppSelector } from './useAppSelector';
2022-11-26 16:38:16 +00:00
/** Get the logged-in account from the store, if any. */
2023-06-25 17:35:09 +00:00
export const useOwnAccount = () => {
2022-11-26 16:38:16 +00:00
const getAccount = useCallback(makeGetAccount(), []);
2023-06-25 17:35:09 +00:00
const account = useAppSelector((state) => {
2022-11-26 16:38:16 +00:00
const { me } = state;
if (typeof me === 'string') {
return getAccount(state, me);
}
});
2023-06-25 17:35:09 +00:00
return { account: account || undefined };
};