trojanowski/react-apollo-hooks

Unable to Access Result Attributes

smooJitter opened this issue · 0 comments

I'm not sure if this is an apollo hooks problem but I'll give it a try. I am using react hooks and react-apollo-hooks.

Here's my query function.

export default function useQueryEvent({ eventId }: Props) {
  ...
  const { data, loading, error } = useQuery(QUERY_EVENT, { variables: { _id: eventId } });

  if (loading) return <Caption text="Loading..." />;
  if (error) return <Caption text="error" danger />;

  const { eventById } = data;

  return {
    event: eventById,
    loading,
    error,
  };
}

Here's my presentation component.

export default ({ eventId, ...props }) => {
  const { event, loading, error } = useQueryEvent({ eventId });
  if (loading) return <Caption text="Loading..." />;
  if (error) return <Caption text="Error" danger />;

  console.log(event);

  console.log(event.profile);

  return (
    ....
  );
};

I can access the "event" object (console log returns) but I can not access the attributes on the object, i.e., console.log(event.profile) is undefined.