M
M
Merle72020-09-18 14:47:50
JavaScript
Merle7, 2020-09-18 14:47:50

How to cancel page reload on button click in React and immediately call another function on the same click?

Hello, there is the following function from the react-speech-recognition library.
It is hung on a button click.


onClick={() => { SpeechRecognition.startListening({ continuous: true, language: 'ru' }) }}

But when you click on the buttons, the page reloads. When you click on it, you need to cancel the reload and perform this function of starting voice recording.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
8
8XL, 2020-09-18
@8XL

const handleClick = (e) => {
 e.preventDefault();
SpeechRecognition.startListening({ continuous: true, language: 'ru' })
}

onClick = { handleClick }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question