bigbuffet-rw/app/soapbox/hooks/useOwnAccount.ts

20 lines
494 B
TypeScript
Raw Normal View History

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