i am trying to add some speech recognition to my react app. If the user says a specific word - 'frog', it allows them to open the next page. However I am stuck in adding this line to my page, because it is a hook it isn't allowed:
const { transcript, resetTranscript } = useSpeechRecognition();
Is there a way to add it without creating a new component, as the button on this page needs to know what has been said and whether to allow the user to proceed.
Below is my code:
export const AuthPage = () => {
const navigate = useNavigate();
//THIS LINE IS CAUSING THE HOOK ERROR
// const { transcript, resetTranscript } = useSpeechRecognition();
const navigateToNextPage = () => {
navigate(`/frogPage/${name}`);};
return (
<main className='simple-wrapper'>
<button onClick={SpeechRecognition.startListening}>Say Word</button>
//ONLY SHOW NEXT BUTTON IF THEY SAID THE WORD FROG CORRECTLY
{transcript.includes("frog") && (
<button onClick={navigateToNextPage}>Next</button>)
</main>
);
};