I am passing a function to a child component in React and it works perfectly when I call it directly in onClick of a button. But then when I move it into a separate function