I started coding my React app w/o thinking too much about how to divvy up the logic between parent and child(ren) components. But now, I think I have put myself in a bind.
I have a function running in a child component that returns a variable which I have to send to parent component in order to send back down to a sibling component.
Child component = searchPantry.jsx
Event in child component = handleCheck(ingredientName)
Variable created in child component = recipes
Sibling component = recipeResult.jsx
Parent component = readData.jsx
All code: https://codesandbox.io/s/wash-po-recipes-4v44s?fontsize=14
I read a couple of blogs on how to send data up to parent from child including [this] (https://blog.bitsrc.io/react-communication-between-components-c0cfccfa996a) one but they are sending data from a JSX element. And I want to send it from a function.
The only solution I can think of is making the variable part of setState…? I think that’s bad coding practice? If anyone has any other ideas, please let me know. At a loss.