diff --git a/app/soapbox/entity-store/hooks/useEntity.ts b/app/soapbox/entity-store/hooks/useEntity.ts index e74e0d5e8..d0bae8630 100644 --- a/app/soapbox/entity-store/hooks/useEntity.ts +++ b/app/soapbox/entity-store/hooks/useEntity.ts @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { useApi, useAppDispatch, useAppSelector } from 'soapbox/hooks'; @@ -12,6 +12,8 @@ type EntityPath = [entityType: string, entityId: string] interface UseEntityOpts { /** A parser function that returns the desired type, or undefined if validation fails. */ parser?: (entity: unknown) => TEntity | undefined + /** Whether to refetch this entity every time the hook mounts, even if it's already in the store. */ + refetch?: boolean } function useEntity( @@ -42,6 +44,12 @@ function useEntity( }); }; + useEffect(() => { + if (!entity || opts.refetch) { + fetchEntity(); + } + }, []); + return { entity, fetchEntity,