Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Calling a function from child component, but it is repeatedly being called

I am trying to call a function that is 2 levels up from my child component (as this will refresh the data sent down in props to my child).

However, the problem I am facing is that the function getBooking is being constantly called. It should only be called once when the form submits in the child component, so not sure how it’s being repeatedly called.

Grandparent:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const getBooking = async (fullReload: boolean) => {
  ...code
}

<BookingGuestList
   getBooking={getBooking(false)}
/>

Parent:

<GuestListRow
   getBooking={getBooking()}
/>

Child:

getBooking();

>Solution :

You need to call the parent function in the following way

Child:-

getBooking={()=> getBooking()}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading