i'm new to react and i have the following problem: useEffect is updating infinite times, but i just want it to update the data when i insert a new record, i would be grateful if someone can correct me.
this is my code:
index.js
import {createUser, getUsers} from '../actions';
const Home = () => {
const [data, setData] = useState([]);
useEffect(() => {
async function fetchData(){
const result = await getUsers();
setData(result);
console.log("teste: ", result);
}
fetchData();
}, [setData]);
const handleCreateUser = (user) => {
createUser(user).then((users) => {
});
};
if i put on the second param useEffect(() => {}, [setData]), it breaks the infinite loop but the table does not update when i insert a new register and I need to use F5.
what am i doing wrong? the create user is working perfectly, i just want to att in the same time the table