我确定我是否遵守规则,但是此功能出现此错误
错误:无效的挂钩调用。挂钩只能在身体内部使用 功能组件。可能发生以下情况之一 原因:
- 您可能使用了不匹配的React和渲染器版本(例如React DOM)
- 您可能正在违反挂钩规则
- 您可能在同一应用中拥有多个React副本
在这里:
import React, { useState, useEffect } from 'react';
import { getAll } from './../../services/events/api';
import EventsList from '../../containers/EventsList';
import IEvent from './../../services/events/models/IEvent';
import Loading from './../../components/Loading';
import Error from './../../components/Error';
const EventList = () => {
const [events, setEvents] = useState<Array<IEvent>>([]);
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState(null);
const fetch = async () => {
try {
setIsLoading(true);
const events: Array<IEvent> = await getAll();
setEvents(events);
setIsLoading(false);
} catch (error) {
setIsLoading(false);
setError(error);
console.log(error);
}
};
useEffect(() => {
fetch();
}, []);
return (
<>
{error ? (
<Error title="Sorry" subtitle="Error loading events" />
) : isLoading ? (
<Loading />
) : (
<EventsList events={events} />
)}
</>
);
};
export default EventList;
错误在哪里?进行无效的挂接调用