'Perform 2 functions OnClick ReactJS
hope you are all good.
I have button onclick that call 2 functions BUT it is not working and i dont have any errors displaying in the console, so i don't know where the problem is.
Here is my code
<div className="d-grid gap-2">
<Bouton btnCss = 'btn btn-success my-3'
click= { () => { this.props.handleSubmit; this.setState({begin : true})}}>
Commencer la tâche
</Bouton>
</div>
</form>
</>
)
}
}
export default withFormik({
mapPropsToValues : () => ({
tache : '',
unite : '',
commentaire : ''
}),
validationSchema : Yup.object().shape({
tache : Yup.number()
.required('Choisissez une tâche'),
unite : Yup.number()
.required('Choisissez une unite'),
commentaire : Yup.string()
.min(5, 'Le Texte est trop court')
.required('Veuillez entre un texte')
}),
handleSubmit : (values, {props, resetForm}) => {
resetForm();
props.validation(values.tache, values.unite, values.commentaire);
}
})
(taskForm)
Thank you for your help mates !
Solution 1:[1]
Why don't you call one function, that calls the next two functions? Something like this:
handleClick() {
function1();
function2();
}
<Bouton btnCss = 'btn btn-success my-3'
onClick= { () => { this.handleClick() }}>
Commencer la tâche
</Bouton>
You can always add async/await if you need to wait for the 1st one to complete before you fire the 2nd one. ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
