给定以下组件,当我按下年龄选择器并将值更改为15时,使我呈现一个没有“驾驶执照”字段的表单时,就会得到错误:
Uncaught Error: Rendered fewer hooks than expected. This may be caused by an accidental early return statement.
at invariant (react-dom.development.js:55)
at finishHooks (react-dom.development.js:11581)
at updateFunctionComponent (re
我尝试的是使用useHistory和useLocation为React组件编写一个测试,如下所示:
import { useHistory, useLocation } from 'react-router-dom';
export function MyComponent() {
let location = useLocation();
let history = useHistory();
function changeUrl(param) {
// some logic here
if(foo) {
history.pus
我试图写一个from,但是它抛出了这个错误:
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 m
我有一个react项目,它在文件中定义了一个Signup元素。代码是
import React, { Component } from 'react';
import Button from 'react-bootstrap/Button';
import Form from 'react-bootstrap/Form';
import { useNavigate } from 'react-router-dom';
import postData from './APIREQ';
class Signup ex
好的,我想我已经浏览了几乎所有RTK查询的文档,并阅读了RTK查询的缓存。这似乎是一个相当大的部分,即使这不是我现在需要的东西。
因此,我尝试在基于类的组件中使用RKT查询执行一个简单的查询,然后从Redux中选择端点调用的isLoading状态。然而,目前在render() {} of my LoginPage.jsx中,endpoint.<name>.select()(state)对LoginPageContainer.jsx中的mapStateToProps的调用似乎不起作用。(见下文代码)。
从上的文档示例来看,我似乎在.select(<cache_key>)(
早上好!
我正在启动react钩子,但是当我想要使用useEffect时,它抛出了以下错误:
Line 4:5: React Hook "useEffect" is called in function "profile" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks
代码如下:
profile.js
import React, { useEffect } from 'react';
错误:
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'
我有一个简单的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
我正在尝试使用jest和react测试库对自定义钩子进行单元测试,在这种情况下抛出错误,但我无法捕获实际的错误消息,以下是我到目前为止的代码:
我的第一个钩子:
import react from 'react';
const useFirstHook = () => {
//I will add conditional logic later
throw new Error('my custom error is thrown')
const test1 = 'I am test 1';
retur
我正在实现一个简单的登录页面,我希望在选择标识后将用户转发到另一个页面/路径。
import {useState} from "react";
import { Navigate } from 'react-router-dom';
import Container from 'react-bootstrap/Container';
import Select from 'react-select';
import './Login.css';
export default function Login(){
我不知道为什么在通过React查询使用突变时会出现这个错误。任何形式的反馈都将不胜感激。
注意:我在一个函数(React)组件中使用,所以我不知道为什么会抛出这个错误。
错误:
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
我正在使用回调钩子来停止渲染组件,这些组件在每个渲染中都是由于作为道具传递的函数的更改而更改的。在这里,我向incrementSalary和incrementAge添加了回调钩子。在这种情况下,回调钩子似乎工作得很好。但是,eslint会抛出以下错误: Line 10:76: React Hook useCallback has an unnecessary dependency: 'age'. Either exclude it or remove the dependency array react-hooks/exhaustive-deps
Line 15
请看下面的代码,由于某种原因,它抛出了"Logout is not a function“: logout.jsx: import React from 'react';
import { Link } from 'react-router-dom';
class Logout extends React.Component {
componentDidMount = () => {
this.props.onLogoutUser();
}
render() {
return (
<
我正在使用一个react挂钩通过axios从covid api获取数据,但是它抛出了一个错误
React Hook useEffect has a missing dependency: 'countries'. Either include it or remove the dependency array react-hooks/exhaustive-deps
哪些国家是我的州
代码:
const [countries,setCountries]=useState([]);
useEffect(()=>{
axios.get('https://
我需要在对特定事件调用的函数中获取上下文的当前值,而不是在呈现器中。
示例:
logCurrentTheme.js
import React, { useContext } from 'react';
import {ThemeContext} from "./ThemeContext";
// ThemeContext is a context created by React.createContext()
function logCurrentTheme() {
const context = useContext(ThemeContext);
我是一个非常非常业余的程序员,但最近我一直在努力学习JavaScript和ReactJS。它并不美观,我不知道大多数东西是做什么的,但我想我应该遵循YouTube教程,了解一些我感兴趣的东西,所以I found one我喜欢它,并遵循它。然而,在8:52中,React抛出了一个无效的钩子调用错误。我的问题是,即使我非常确定文档中有一个解决方案,但我的业余水平不允许我阅读和理解它。基本上:我不知道文档是怎么说的。下面是错误的附加屏幕截图(如果有人要求我向下滚动,还有更多)和完整代码的链接。如果有人能提供帮助,那将是令人惊讶的,但根据评论的数量和缺乏承认这个错误的人,我认为它很难重现。此外,如果