我正在使用React 16,并尝试使用React钩子来访问上下文。
const { locale } = React.useContext(LocaleContext);
这个钩子调用是在Redux中间件中完成的。然后我得到了错误Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component.
有没有办法让我从功能组件外部访问上下文?
当我在我的应用程序中输入内容UI代码并在浏览器上启动我的react应用程序时。我的应用程序警告:
22. Stack frames were collpsed.
-------------------------------
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
我们有没有办法在getStaticProps().中使用自定义钩子?原因是,因为我们使用内容CMS从传递API中获取数据,而且我们更容易使用自定义钩子来获取某些数据。
现在,当我们调用(例如,useHomePageData中的getStaticProps()函数)时,当我们试图使用简单的对象析构来获取数据时会出现错误。
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 r
当试图在使用"rfc"-snippet生成的函数组件中初始化Date对象时,component将抛出下面的错误。组件里没有钩子。除了代码片段之外,let dateObj = new Date()是惟一添加的内容。
我已经检查了我的React版本,并尝试重新启动服务器。我使用创建-反应-应用程序来创建我的反应项目。
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
import React from 'react
如何使用旧的react useContext ()函数进行渲染?
错误:
react-dom.development.js:57 Uncaught (in promise) Invariant Violation: 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
我正在使用redux/toolkit处理简单的reactjs登录表单。成功登录后,我想重定向到dashboard页面。它正在抛出跟随错误。我是新手,如果我错过了什么,请告诉我。
错误:
Uncaught (in promise) Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
authSlice.js
import { useNavigate } from 'react-router-dom';
export const submit
我试图在React中的一个函数中使用useParams()钩子,但是它给出了以下错误
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 b
我在试着得到一个正常运作的反应表。我已经把我的项目简化到了基本的调试过程,我不明白为什么这是一个无效的钩子,有什么方法可以让我更好地了解什么是错误,还是我没有正确地读取错误?
在和下运行时出现的错误--和底部的所有代码
react.development.js:209 Warning: 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 hav
我正在尝试更新组件的状态,但由于某种原因,它一直显示为Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
我正在尝试有一个模式,可以打开一次点击一个<div>。在该模式中有一个文本输入,它将更新状态(备注)。出于某种原因,它说钩子调用无效--为什么呢?
const openTestModal = () => {
let [notes, setNotes] = useState("");
let [
我是个新手,我得到了以下错误:
react-dom.development.js:14906 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
我在尝试创建一个模式时出现错误。我尝试制作一个在单击按钮时出现的模式。这是一个在modal中弹出的表单,提交后modal将关闭。表单是一个常规组件,直到我更改了流程,所以我更改了组件,使其成为一个模式。在这样做之后,我得到了这个错误。
Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
而且我的状态也不再起作用
Line 7:4: 'state' is not defined no-undef
提一下我还是个新手可能会更好。
这是我制
Unhandled Rejection (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
我从here复制粘贴了演示,但它似乎不能在我的应用程序中工作。不确定与我的代码和网站上的代码有什么不同。我得到以下错误: react-dom.development.js:14724 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:
VM15341 makeStyles.js:170 Uncaught TypeError: Can
我有一个简单的service.js,如下所示:
import axios from 'axios'
import { useContext } from 'react'
import APIContext from '../context/api/context'
function GetApi() {
const { API } = useContext(APIContext)
console.log(API)
return API
}
const api = axios.create({
baseURL: `${GetAp
我正在学习React,在一个应用程序中,我试图改变描述和数量,并添加一个注释,但是每次我尝试,我都会得到一个错误:
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
我想把一个钩子放在初始化变量的状态中: state = {
geo: new usePosition()
} 但我得到了以下错误: 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 D
当我介绍useQueryClient时,我正在经历以下错误?知道为什么会这样吗?
我正试图通过invalidateQueries获得一个queryKey onSuccess of useUpdateEmployee hook。
bundle.js:1427 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:
组件
import { use
好吧,我有个错误
Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
我尝试了很多不同的方法来解决这个问题,但我失败了。
这是我的密码
export const DataInput = () => {
const Post = (testTitle, testText) => {
useFirestore().collection('schedule-data').doc('test
所以最近我开始将React漂亮的dnd集成到我的React项目中,我编写了一堆代码并得到了这个错误:
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
这是:
The above error occurred in the <DragDropContext> component:
at DragDropContext (http://127.0.0.1:3000/static/js/bundle.js:8960:19)
at
我正在使用react-i18next模块和useTranslation钩子转换。我可以在我的组件上使用它。但我想在redux操作中使用它。Error: Invalid hook call. Hooks can only be called inside of the body of a function component.。
import cogoToast from "cogo-toast";
import { useTranslation } from "react-i18next";
export const test = ({ key1, key2
我想在我的DApp中包含DApp( include ),但是我在控制台中得到了这个错误,因为其他组件也没有呈现这个错误:
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
当我在我的应用程序上使用钩子时,我得到了的错误:无效的钩子调用。我不知道为什么要得到这个错误,因为我认为它是在函数组件中调用的?
Server Error
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 R
我想编写一个我将在不同功能组件中使用的通用函数。
这个通用函数使用钩子,我得到了错误:Error: Invalid hook call. Hooks can only be called inside the body of a functional component.
我的代码示例:
App.js
import React from 'react';
import {
Text,
TouchableOpacity,
} from 'react-native';
import { Change } from 'static/Change
所以,在我的下一个应用程序中,我使用的是react-google-one-tap-login库,它有useGoogleOneTapLogin钩子,必须在react组件内部调用。但当我称之为:
func() {
useGoogleOneTapLogin({})
return (some jsx)
}
我发现了一个错误ReferenceError: window is not defined。
然后,我将尝试使用if (process.browser)然后运行useGoogleOneTapLogin来修复它,但是我得到了一个错误:useGoogleOneTapLogin is called
我正在使用Firebase Cloud Functions托管我的SSR Nextjs应用程序。我可以在firebase云函数上部署Nextjs应用程序,并在没有React Hooks的情况下通过干净的URL访问它,但使用React Hooks时,我会收到一条错误消息:
Invariant Violation: 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.
不允许在高阶组件中使用钩子吗?当我尝试用这个简单的模式来做这件事时,我得到了错误Invalid hook call. Hooks can only be called inside of the body of a function component. // App.js
import React, { useState } from 'react';
const WithState = (Component) => {
const [state, dispatch] = useState(0);
return () => <Component