简体   繁体   English

反应原生。 错误:无效的挂钩调用。 钩子只能在 function 组件的主体内部调用

[英]React Native. Error: Invalid hook call. Hooks can only be called inside of the body of a function component

My App was working fine and suddenly i got this error.我的应用程序运行良好,突然我收到了这个错误。

Error: Invalid hook call.错误:无效的挂钩调用。 Hooks can only be called inside of the body of a function component.钩子只能在 function 组件的主体内部调用。 This could happen for one of the following reasons:这可能由于以下原因之一而发生:

  1. You might have mismatching versions of React and the renderer (such as React DOM)你可能有不匹配的 React 版本和渲染器(例如 React DOM)

  2. You might be breaking the Rules of Hooks您可能违反了 Hooks 规则

  3. 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.您可能在同一个应用程序中拥有多个 React 副本,请参阅https://reactjs.org/link/invalid-hook-call以获取有关如何调试和修复此问题的提示。

     import { useContext } from "react"; import jwtDecode from "jwt-decode"; import AuthContext from "./context"; import authStorage from "./storage"; const useAuth = () => { const { user, setUser } = useContext(AuthContext); const logIn = (authToken) => { const user = jwtDecode(authToken); setUser(user); authStorage.storeToken(authToken); }; const logOut = () => { setUser(null); authStorage.removeToken(); }; return { user, logIn, logOut }; }; export default useAuth;

All looks fine.一切看起来都很好。 except maybe actually importing React除了可能实际导入 React

import React, { useContext } from "react";

I know you don't need this for React from React 17, but there's no official statement from react native saying they use the new JSX compiler that doesn't require the import statement我知道 React 17 中的 React 不需要这个,但是 react native 没有官方声明说他们使用不需要 import 语句的新 JSX 编译器

also check the AuthContext file you imported还要检查您导入的 AuthContext 文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Native:错误:无效的挂钩调用。 钩子只能在 function 组件的主体内部调用 - React Native: Error: Invalid hook call. Hooks can only be called inside of the body of a function component 反应本机:.! 错误:无效的挂钩调用。 钩子只能在 function 组件的主体内部调用 - React Native !!! Error: Invalid hook call. Hooks can only be called inside of the body of a function component 反应钩子错误:无效的钩子调用。 钩子只能在 function 组件的主体内部调用 - React hook Error: Invalid hook call. Hooks can only be called inside of the body of a function component React 17:错误:无效的钩子调用。 钩子只能在 function 组件的主体内部调用 - React 17: Error: Invalid hook call. Hooks can only be called inside of the body of a function component 反应,得到错误:无效的钩子调用。 Hooks 只能在函数组件的主体内部调用 - React, getting Error: Invalid hook call. Hooks can only be called inside of the body of a function component React - 错误:无效的钩子调用。 钩子只能在 function 组件的主体内部调用 - React - Error: Invalid hook call. Hooks can only be called inside of the body of a function component 错误:无效的挂钩调用。 钩子只能在 function 组件的主体内部调用。 通过路由反应 - Error: Invalid hook call. Hooks can only be called inside of the body of a function component. by Routing in react 错误:无效的挂钩调用。 钩子只能在 function 组件的主体内部调用。 - 反应 - Error: Invalid hook call. Hooks can only be called inside of the body of a function component. - React “错误:无效的钩子调用。只能在 function 组件的主体内部调用钩子。”在反应原生 expo - "Error: Invalid hook call. Hooks can only be called inside of the body of a function component.." in react native expo 收到此错误“无效的挂钩调用。 钩子只能在 function 组件的主体内部调用。” 在反应功能组件内? - Getting this error “Invalid hook call. Hooks can only be called inside of the body of a function component.” inside a react functional component?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM