2022-11-26 08:38:16 -08:00
|
|
|
import { useCallback } from 'react';
|
|
|
|
|
2022-03-23 18:29:35 -07:00
|
|
|
import { useAppSelector } from 'soapbox/hooks';
|
|
|
|
import { makeGetAccount } from 'soapbox/selectors';
|
|
|
|
|
2022-03-24 12:27:27 -07:00
|
|
|
import type { Account } from 'soapbox/types/entities';
|
2022-03-23 18:29:35 -07:00
|
|
|
|
2022-11-26 08:38:16 -08:00
|
|
|
/** Get the logged-in account from the store, if any. */
|
2022-03-23 19:05:55 -07:00
|
|
|
export const useOwnAccount = (): Account | null => {
|
2022-11-26 08:38:16 -08:00
|
|
|
const getAccount = useCallback(makeGetAccount(), []);
|
|
|
|
|
|
|
|
return useAppSelector((state) => {
|
|
|
|
const { me } = state;
|
|
|
|
|
|
|
|
if (typeof me === 'string') {
|
|
|
|
return getAccount(state, me);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
});
|
2022-03-23 18:29:35 -07:00
|
|
|
};
|