I was curious to know if making an API
request outside of the lifecycle/useEffect is a valid way to make the call?
https://stackblitz.com/edit/react-useeffect-button has two functional components, the parent component makes an API
call and passes the data to the child component
, initially specified the limit of data to be fetched from the endpoint as 2 and the parent component has a LoadMore
function that is passed as a prop
along with the data to the child component
.
Using the react-slick slider
to display the images in the child component
and the Load button onClick
will call the function LoadMore
inside the parent component and then it makes an API call and appends the new data from API to the old Data. The load button will append one Image to the existing images.
is this a good way to make API requests or should it be done only in the lifecycle methods?