-1

I'm trying to set admin with data.currentAdmin from

export const AuthContextProvider: FC<Props> = ({ children }) => {
  const [admin, setAdmin] = useState<Admin | null>(null);
  const [currentAdmin, { data }] = useCurrentAdminLazyQuery();

  const fetchCurrentAdmin = async () => {
    await currentAdmin();
  };

  useEffect(() => {
    fetchCurrentAdmin();
  }, []);

  setAdmin(data.currentAdmin);

  return (
    <AuthContext.Provider value={{ admin }}>{children}</AuthContext.Provider>
  );
};

I receive error:

TypeError: Cannot read property 'currentAdmin' of undefined
  • https://www.apollographql.com/docs/react/data/queries/ - loading is for sth ... lazy is on request, too ... data is available only after data load, rendering/accessing data props before that will fail, OBVIOUSLY – xadm May 06 '21 at 15:25

0 Answers0