my code is below:
const [todos, setTodos] = useState('');
I am using a fake server.
function getTodos () {
axios.get('http://localhost:4000/todos')
.then(function (response) {
setTodos(response.data);
})
.catch(function (error) {
console.log(error);
})
.then(function () {
});
}
<tbody id="tableBody">
{
todos.map((item) => (
<tr key={item.id}>
<td>{item.id}</td>
<td>{item.task}</td>
<td>{item.desc}</td>
<td>{item.due}</td>
<td>{item.status}</td>
</tr>
))
}
</tbody>
But I am getting this error: TypeError: todos.map is not a function
const [todos, setTodos] = useState('');when the component renders first,todosis a string. Useconst [todos, setTodos] = useState([]);instead.