My goal is to run the apollo query hook (useDataAboutThing), get the part of the data object I need, and get that resulting data into event with setEvent. Every attempt I try at solving this, I violate the law of hooks or create a feedback loop. This seems like it should be easy which probably means I have a flawed understanding of React that needs to be corrected.
type ComponentProps = {
id: number;
}
const Component = ({ id }: ComponentProps) => {
const { data, loading, error } = useDataAboutThing({
variables: {
id: id,
},
});
const [event, setEvent] = React.useState([]);
// without checking these, data is undefined
if (loading) return <div>Loading...</div>;
if (error) return <div>Error!</div>;
const dataInformation = data.information;
React.useEffect(() => {
setEvent(dataInformation)
}, []) // Error: Rendered more hooks than during the previous render.
return (
...
);