我正在使用打字稿和React开发网页。
调用API时,我是否声明所有响应的interface
?
这是我的React代码。
// Do I have to do this all times ?
interface DataObj {
bred_for: string;
breed_group: string;
height: { [key: string]: string };
id: number;
life_span: string;
name: string;
origin: string;
temperament: string;
weight: { [key: string]: string };
}
const Main: React.FC<{}> = () => {
const [data, setData] = useState<DataObj[] | null>(null);
useEffect(() => {
const fetchBreeds = async () => {
const data: AxiosResponse = await apis.getBreeds();
setData(data.data);
};
fetchBreeds();
}, []);
return (
...
我不想写整个回复的key
。救救我!