Reputation: 49
When I try to create an element of my "Question" type, like this from an external component:
const current = Question();
Being the Question component as follows:
export const Question = () => {
const [text, setText] = useState("None");
return (
<>
<div className="row">
<div className="col-12 col-md-9 col-lg-10 col-xl-10 col-xxl-10">
<span>{text}
</span>
</div>
</div>
</>
)
}
When I try to create that Question object, it returns the following error:
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
What can be happen? I'm not calling Hooks from a JS function.
Thanks.
Upvotes: 0
Views: 76
Reputation: 89314
Do not try to call the component function directly. Instead, use JSX:
const current = <Question/>;
Upvotes: 1