首页 > 其他分享 >2023-10-24 Too many re-renders. React limits the number of renders to prevent an infinite loop. ==》组

2023-10-24 Too many re-renders. React limits the number of renders to prevent an infinite loop. ==》组

时间:2023-10-24 15:23:13浏览次数:24  
标签:prevent 渲染 number React renders 组件

React报错:

Too many re-renders. React limits the number of renders to prevent an infinite loop. 重新渲染过多。React限制渲染次数,以防止出现无限循环。

解决方案:查看你最近写的代码,比如我写了一个函数组件,我在函数组件里面写了直接执行的任务,这将导致状态变化,react会重新渲染,

react有个防止无限渲染的函数,正是触发了这个函数才报这个错误。

错误写法:

onClick={setUseModal(true)}

正确写法:

onClick={()=>setUseModal(true)}

这样就不会报错了。

标签:prevent,渲染,number,React,renders,组件
From: https://www.cnblogs.com/iuniko/p/17784885.html

相关文章

  • Java中的NumberFormatException异常常见原因是什么?
    Java中的NumberFormatException异常常见原因是什么?Java中的NumberFormatException是一种常见的异常,它通常在字符串转换成数值类型时发生。本文将探讨NumberFormatException异常的原因及解决方法。引起NumberFormatException异常的原因:字符串转换成数值类型时格式错误。例如,对于......
  • vue2 el-input-number 千分位显示的支持(不影响v-model的数值取值)
    <!--增加v-thousands指令--><el-input-numberv-model="row.money"v-thousands:controls="false":min="0":precision="2"style="width:100%"//添加全局指令或局部指令directives:......
  • [ABC234E] Arithmetic Number 题解
    题目传送门一道枚举题。暴力枚举数字位数、首位、等差数列的公差即可。注意公差的枚举范围,并且需要看看末尾合不合法。顺便提一下,我是用字符串存储枚举的数字的,所以写了一个check函数代替大于号。Code#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;......
  • Oracle 查询排名第几到第几行的数据(rownumber效率最高)
    查询排名第5到第10行的数据  实现效率最高,如果是在前端页面用循环选择,效率是很慢的。ROWNUM是Oracle加在查询数据集的伪字段,记录的是每一行的行号。--第三步查询需要的几行数据SELECTA.NAME,A.FW_TIMESTAMPFROM(--第二步加排序编号ROWNUMSELECTA.NAME,A.FW_TIMES......
  • CF367C Sereja and the Arrangement of Numbers
    这题首先上来会发现题目中的很多信息都是假的,核心就是问要构造一个\(x\)个点的完全图至少要多长的序列我们把序列中相邻的两个元素看作图上的一条边,则可以把问题转化为:给一个\(x\)个点的完全图,问至少要走多长的路径才可以遍历图中的所有边至少一次简单讨论下会发现当\(x\)为奇数......
  • iview2.0 InputNumber 保留两位小数
    <FormItemprop="free"label="包期费用(元):"><Input-number:min="0"style="width:100%"v-model="formValidate.free"placeholder="请输入单价(元)&......
  • PAT_A 1038 Recover the Smallest Number
    Givenacollectionofnumbersegments,youaresupposedtorecoverthesmallestnumberfromthem.Forexample,given{32,321,3214,0229,87},wecanrecovermanynumberssuchlike32-321-3214-0229-87or0229-32-87-321-3214withrespecttodifferentor......
  • [906] Replace NaN (Not-a-Number) values with 'Null' in Pandas
    InPandas,youcanreplaceNaN(Not-a-Number)valuesinaDataFramewithNone(Python'sNonetype)ornp.nan(NumPy'sNaN)values.Here'showyoucanreplaceNaNvalueswithNone:importpandasaspdimportnumpyasnp#CreateasampleDa......
  • What is @RenderSection in asp.net MVC - Stack Overflow
    [email protected]@RenderSectionandhowdoesitfunction?Iunderstandwhatbundlesdo,butIhaveyettofigureoutwhatthisdoesandit'sprobablyimportant.@RenderSection("scrip......
  • vue @click.native/stop/prevent
    [email protected]父组件要引用子组件中的点击事件,可以通过@click.native来直接访问子组件中的方法,如果不使用@click.native可在子组件中使用this.$emit('click')来传递事件//父组件<template><div><span>父组件页面</span><search@click="onSubmit"></search&g......