what is the error in this react component ?
import React, { useState, useEffect } from 'react';
import axios from 'axios';
const Tasks = () => {
const [tasks, setTasks] = useState([]);
useEffect(() => {
axios.get('/tasks').then(response => setTasks(response.data));
return (
<ul>
{renderList(tasks)}
</ul>
);
},[]);
};
renderList(tasks) {
console.log(tasks)
return <li>dd</li>
}
export default Tasks;
I can not figure out the error .. seems easy but i dont know where is my error .
./src/compononents/Tasks.js
Line 16: Parsing error: Unexpected token, expected ";"
14 | };
15 |
> 16 | renderList(tasks) {
| ^
17 | console.log(tasks)
18 | return <li>dd</li>
19 | }
Taskcomponent returnsundefinedsince you're returning inside theuseEffectinstead. Then, it looks like you're confusing the function declaration syntax with the method definition syntax.