Closed. This question is not reproducible or was caused by typos . It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 hours ago.
Improve this question
I am using useNavigate and this error is coming:
Uncaught Error: Invalid hook call. Hooks can only be called inside the body of a function component. This could happen for one of the following reasons:
- You might have mismatching versions of React and the renderer (such as React DOM)
- You might be breaking the Rules of Hooks
- You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
The code is following:
import React, { useContext, useEffect } from 'react';
import { useNavigate } from "react-router-dom";
function Recipeitem() {
let navigate = useNavigate;
const gotoRecipes = ()=>{
navigate(`/recipe`);
}
return (
<button onClick={()=>{gotoRecipes()}}>Go to Page</button>
);
}
I have tried many solutions but doesn't work. Please help.
I appreciate any help you can provide.
1条答案
按热度按时间n6lpvg4x1#
useNavigate是一个react钩子(函数)而不是一个值。你必须用
()
来调用它。