generated from Luis/nextjs-python-web-template
some final fixes before the demo
This commit is contained in:
19
pkgs/ui/src/components/hooks/useGetEntityById.tsx
Normal file
19
pkgs/ui/src/components/hooks/useGetEntityById.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { useContext } from "react";
|
||||
import { AppContext } from "./useAppContext";
|
||||
|
||||
const useGetEntityByName = (nameOrDid: string) => {
|
||||
const { data } = useContext(AppContext);
|
||||
const allEntities = data.allEntities;
|
||||
|
||||
if (!allEntities) {
|
||||
return { entity: undefined, isLoading: true };
|
||||
}
|
||||
|
||||
const entity = allEntities.find(
|
||||
(entity) => entity.name === nameOrDid || entity.did === nameOrDid
|
||||
);
|
||||
|
||||
return { entity, isLoading: false };
|
||||
};
|
||||
|
||||
export default useGetEntityByName;
|
||||
Reference in New Issue
Block a user