How to call child method inside parent component?
Code is more complicated, but I did my best to simplify it for u guys.
const Parent = (history) => {
function triggerChildMethod (e) {
}
return (
<div>
<Child history={history}/>
</div>
)
}
function mapStateToProps(state){ //I used redux here and inside child too
return {state};
}
function mapDispatch (){
... /// I just simplified here
}
export default connect(mapStateToProps, mapDispatch)(Parent);
Child have one method that needs to be call from parent:
class Child extends React.Component{
function needsToBeCalled = () => {
}
}
mapStateToProps(state){
return {blabla: state};
}
export default connect(mapStateToProps, mapDispatch)(PostsList);