I'm trying to understand why my function is called 5 times. The function return nothing the first 3 times and then twice with the data. I would like it to run only only once, when the data are ready.
Parent component:
export default function PublicCircles() {
const [circles, getCircles] = useState('');
const accessToken = window.localStorage.getItem('accessToken')
useEffect(() => {
getPublicCircles();
}, []);
const getPublicCircles = () => {
const headers = {
'Content-Type': 'application/json',
'Accept-Language': 'fr',
'Authorization': `Bearer ${accessToken}`,
}
axios.get('https://myurl.com/api/get-public-circles?lang=All', { headers })
.then((response) => {
const publicCircles = response.data.data;
getCircles(publicCircles);
})
.catch(error => console.log('error', error))
};
return (
<PublicCircle circles={circles} />
)
}
Child component:
export default function PublicCircle(props) {
console.log(props.circles)
return(
<>
</>
)
}
Thank you.
