From 00aa373997471948817cda7c3c71ec260f4ab411 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 6 Apr 2024 20:45:54 -0500 Subject: [PATCH] useEntityLookup: fix lookup redirect --- src/entity-store/hooks/useEntityLookup.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/entity-store/hooks/useEntityLookup.ts b/src/entity-store/hooks/useEntityLookup.ts index a54882d6f..3ae97b704 100644 --- a/src/entity-store/hooks/useEntityLookup.ts +++ b/src/entity-store/hooks/useEntityLookup.ts @@ -25,10 +25,11 @@ function useEntityLookup( const { schema = z.custom() } = opts; const dispatch = useAppDispatch(); + const [fetchedEntity, setFetchedEntity] = useState(); const [isFetching, setPromise] = useLoading(true); const [error, setError] = useState(); - const entity = useAppSelector(state => findEntity(state, entityType, lookupFn)); + const entity = useAppSelector(state => findEntity(state, entityType, lookupFn) ?? fetchedEntity); const isEnabled = opts.enabled ?? true; const isLoading = isFetching && !entity; @@ -36,6 +37,7 @@ function useEntityLookup( try { const response = await setPromise(entityFn()); const entity = schema.parse(response.data); + setFetchedEntity(entity); dispatch(importEntities([entity], entityType)); } catch (e) { setError(e);