@mukwende2000
Posted
First of all this is not a form, so handleSubmit doesn't fit as a name for the click handler. handleClick would be better, you shouldn't fetch data outside of a useEffect, so the handleSubmit should not be fetching the data, instead i suggest you set a certain state and change the state when you click the button, and to trigger the fetch, you can add that state in the dependecy array. Lastly i really can't see the reason why your looping through the slip. It is not an array you can just do fine by extracting the id and the advice directly into the jsx.
Marked as helpful
@ify47
Posted
@mukwende2000
thanks for the feedback, i have made the necessary changes, i understood my mistakes and learned from it,
Also i am passing a usEffect to call the api on page load once, I look forward to getting more feedback from you, thanks :)