speechRecognition.jsx
import { useRef } from "react";
const CharacterState = {
Idle: 0,
Listening: 1,
Speaking: 2,
};
const useSpeechRecognition = () => {
const [characterState, setCharacterState] = useState(CharacterState.Idle);
const onSpeechFoundCallback = useRef((text) => {});
const setOnSpeechFoundCallback = (callback) => {
onSpeechFoundCallback.current = callback;
};
const onMicButtonPressed = () => {
return true;
};
return {
onMicButtonPressed,
setOnSpeechFoundCallback,
};
};
export default useSpeechRecognition;
Here i am importing
import useSpeechRecognition, {
CharacterState,
} from "../apis/speechRecognition";
const {
onMicButtonPressed,
setOnSpeechFoundCallback,
} = useSpeechRecognition();
Here is my code where i have some inner functions which i am importing and using in child function.
I am getting below error.
Experience.jsx: 8 Uncaught SyntaxError: The requested module ‘/src/apis/speechRecognition.js’
does not provide an export named ‘CharacterState'(at Experience.jsx: 8: 3)
Please check what can be the issue.
3
Answers
If you want to use a function in a child component that was declared in the parent, you can simply pass the function as a props to the child from the parent.
I think you just forgot to export
CharacterState
.