I am working on React. I am having following component
export default function ShowUsers() {
const [users, setUsers] = React.useState([]);
const classes = useStyles();
// userData function returns array of components after fetching data from server with a GET request.
// I have passed setUsers function to set the value of users after fetching from server.
var userData = GetUserData(classes, setUsers, users);
useEffect(() => {
setUsers(userData);
}, []);
return (
<div style={divStyle}>
{userData}
</div>
);
}
This code is calling the GetUserData
function and making the GET
request infinitely.
Could you please help me to find what is wrong in this code and if someone can just explain the cause and solution with a little explanation, I would be greatful.
Thanks