Files
mastodon/app/javascript/flavours/glitch/hooks/useAccount.ts
Echo d748ed0434 [Glitch] Account header split up
Port f2fb232e37 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2026-01-15 19:14:19 +01:00

27 lines
793 B
TypeScript

import { useEffect } from 'react';
import { fetchAccount } from '../actions/accounts';
import { createAppSelector, useAppDispatch, useAppSelector } from '../store';
export const accountSelector = createAppSelector(
[
(state) => state.accounts,
(_, accountId: string | null | undefined) => accountId,
],
(accounts, accountId) => (accountId ? accounts.get(accountId) : undefined),
);
export function useAccount(accountId: string | null | undefined) {
const account = useAppSelector((state) => accountSelector(state, accountId));
const dispatch = useAppDispatch();
const accountInStore = !!account;
useEffect(() => {
if (accountId && !accountInStore) {
dispatch(fetchAccount(accountId));
}
}, [accountId, accountInStore, dispatch]);
return account;
}