我在使用usestate()钩子进行状态操作后遇到问题。
无法编译错误:
./src/App.js
Line 6:43: React Hook "useState" is called in function "app" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks
Line 14:39: React Hook "useState" is called in functio
技术
React(17.0.2)React Native(0.66.4)TypeScript(4.4.4)Storybook @storybook/react-native(5.3.25)@storybook/react-native-server(5.3.23)
我面对的是什么
在我的故事书中,我面临着下面的反应钩子错误。
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the followin
错误:
React Hook "useState" is called in function "createFlight" that is
neither a React function component nor a custom React Hook function.
React component names must start with an uppercase letter react-
hooks/rules-of-hooks
我的代码:
import React, {Component} from 'react'
我有一个使用钩子useCallback的功能组件。过去几天一切都很好。一切都正常运作。今天我启动了这个应用程序,我有一个错误:
React Hook "useCallback" is called in function "loginPage" which is neither a React function component or a custom React Hook function
这是没有道理的,因为它一直很好。为了调试,我只是删除了页面上的所有代码,只是其中一段代码经过了编辑,甚至只是将一个useCallback模板放在了原来的位置,但仍然一样。
我试图在我的功能组件中使用React useState钩子,但是我得到了这个错误:
Failed to compile
./src/Person/Person.js
Line 5:43: React Hook "useState" is called in function "person" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks
Search for the keywords to le
我是个新手,我得到了以下错误:
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
在Javascript和Typescript中,(箭头)函数被认为是一等公民。因此,我希望在我的React状态下可以有函数类型。然而,React Hook useState似乎不能很好地处理函数类型。
我有以下代码:
import React, { useState } from "react";
function callApi(num: number): number {
console.log(`Api called with number ${num}. This should never happen.`);
return num;
}
type Comm
在我的react本机应用程序中,我已经开始使用自定义钩子,我创建了一个钩子来检索用户坐标,但是当我的useGeolocation钩子被调用时(在handleUpdateLocation方法中),我总是收到以下警告:
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 Rea
我得到了这个错误,我真的不能解决它: src/api/ConnectApi.js
Line 25:8: React Hook useEffect has missing dependencies: 'apiurl', 'dataState', and 'fetch'. Either include them or remove the dependency array. You can also do a functional update 'setDataState(d => ...)' if you only n
我有一个组件,它使用另一个组件作为呈现器。但是,React不允许我在呈现器组件中使用钩子,因为它会引发以下错误:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
下面是显示组件中的一个示例,它是一个错误边界
class DisplayComponent extends Component {
// ...
render() {
const { rendererComponent } = this.props;
return re
我在React Native应用程序中尝试获得准确的计时时遇到了一个问题。下面是我的问题的一个基本版本。 我可以通过使用setTimeout让它工作,但是它不准确,我正在尝试使用useTimer,这是一个精确的计时器。但是,当我在useEffect中而不是在组件主体中创建计时器时,我得到了一个Invalid Hook Call, Hooks can only be called inside the body of a function component 正在努力寻找解决这个问题的方法。 import React from "react";
import { View, T
我有一个函数,每次名称状态改变时都会调用该函数。我想把这个更改后的值发送给父组件,但它指出了这个错误:
React Hook "useEffect" is called in function "handleNameChange" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks
代码:
export default function config({ me, setMePut }) {
co
import {useState} from 'react'
const nav = () => {
const [activeNav, setActiveNav] = useState('#')
}
我想建个导航吧。我搞错了,我不知道为什么
React Hook "useState" is called in function "nav" that is neither a React function component nor a custom React Hook function. React compone