I am working on an app in react native. I have a custom component (let’s call it child component) which has a button in it. In the parent component, I am using a Flatlist to render a list of the child components given a dataset.
What I want to do is to given a condition, programmatically press the button in one of the rendered child components.
I know the Flatlist renderItem function provides an index parameter which I could potentially use to target a specific child component and leverage forwardref and useref to call the ChildComponentRef.current.props.onPress().
However, that approach means that I would have to force a re-render of parent component (using useState hook) each time I need to press a button in one of the child components.
Is there a way to call the onPress from outside of renderItem to avoid costly re-renders?