I\'m trying to find the proper way to define some components which could be used in a generic way:
I think a render prop is the appropriate way to handle this scenario
You let the Parent provide the necessary props used in child component, by refactoring the Parent code to look to something like this:
const Parent = ({children}) => {
const doSomething(value) => {}
return children({ doSomething })
}
Then in the child Component you can access the function provided by the parent this way:
class Child extends React {
onClick() => { this.props.doSomething }
render() {
return ();
}
}
Now the fianl stucture will look like this:
{(doSomething) =>
(
)}