react how to stop infinite loop on useeffect on initial fetch code example
Example: React looping hooks to display in other hook
import React, { useState } from "react";
function App() {
const [list, setList] = useState(" ");
const [items, updateOnClick] = useState([ ]);
function updateList(event) {
const valueEntered = event.target.value;
setList(valueEntered);
}
function updateClick(){
updateOnClick(list);
}
return (
<input onChange={updateList} type="text" value={list} />
<button onClick={updateClick}>
<span>Add</span>
</button>
<div>
<ul>
{items.map(item => <li>{item}</li>) }
</ul>
</div>);}
export default App;