quiz4
quiz4
b) They can use hooks like useState and useEffect to manage state and side effects
d) useComponent
b) 1
1. Analyze the following code and explain what it does. Identify any potential
issues.
jsx
Copy
const App = () => {
const [data, setData] = useState([]);
useEffect(() => {
fetch('https://api.example.com/data')
.then((res) => res.json())
.then((data) => setData(data));
}, []);
return (
<ul>
{data.map((item) => (
<li key={item.id}>{item.name}</li>
))}
</ul>
);
};
This code fetches a API, do a request and asignes a key and renders the list with
data
When you click the button the value updates, if coponet is mounted it Will put
"component mounted" and if is not it Will put "component unmouted"
GitHub:
https://github.com/Tornike765/quiz4