【发布时间】:2022-08-14 01:17:38
【问题描述】:
import React from \'react\'
import { useParams, useEffect, useState } from \'react\'
import axios from \"axios\";
import \'./App.css\';
const Todo = () => {
const [todoDetails, setTodoDetails] = useState();
const { id } = useParams();
useEffect(() => {
// I wanted to fetch the data for the specific id from the jsonPlaceholder url to practice
axios
.get(`https://jsonplaceholder.typicode.com/todos/${id}`)
.then((res) => {
const responseTodo = res.data;
setTodoDetails(responseTodo);
});
}, [])//the console said the error is here but i don\'t know what to do
// the error is \" Line 17:6: React Hook useEffect has a missing dependency: \'id\'. Either include it or remove the dependency array react-hooks/exhaustive-deps\"
const { id: todoId, userId, title, completed } = todoDetails || {}
return (
<div>{`this is the todoes componets and the id is ${todoId} , ${userId}, ${title}, ${completed}`}</div>
)
}
export default Todo;
**我是开发人员世界的新手,我刚开始学习 JS。我被要求使用 React js 做一个项目,任何提示都会真正帮助我**
-
}, [])=>}, [id])(请先google错误信息)
标签: javascript reactjs react-hooks dependencies