You can call it from an event handler e.g. onClick or any of the React component lifecycle hooks e.g. componentdidupdate.
Or even in the constructor...
Simply:
class MyComp extends React.Component {
constructor(props) {
super(props)
this.props.functionA();
}
componentDidMount() {
...
}
onClick() {
this.props.functionA()
}
componentDidUpdate(prevProps) {
if(somecondition) {
this.props.functionA();
}
}
render() {
return <div onClick={this.onClick.bind(this)} />;
}
}
You only need to use async/await if you need to wait for some async action e.g. Promise to resolve.
class MyComp extends React.Component {
async onClick() {
await this.props.functionA()
doSomethingAfter()
}
render() {
return <div onClick={this.onClick.bind(this)} />;
}
}
EDIT - call a redux action like this:
import { actionName } from 'actions/myactions';
Then call it from within your component:
class MyComp extends React.Component {
onClick() {
this.props.functionA()
}
render() {
return <div onClick={this.onClick.bind(this)} />;
}
}
Then bind the function to your action and connect up to redux:
const mapDispatchToProps = dispatch => ({
FunctionA: () => dispatch( actionName() )
});
Now connect your component to your mapped action and the redux store:
export default connect( mapStateToProps, mapDispatchToProps )( MyComp );