jjzjj

componentDidupdate

全部标签

javascript - 超过最大更新深度。当组件在 componentWillUpdate 或 componentDidUpdate 中重复调用 setState 时,可能会发生这种情况

我正在制作这个Conway的生命游戏React项目,它工作得很好,但是当我添加最后几个按钮来清除棋盘时,React的一些其他功能给了我这个错误Maximumupdatedepthexceeded.ThiscanhappenwhenacomponentrepeatedlycallssetStateinsidecomponentWillUpdateorcomponentDidUpdate.Reactlimitsthenumberofnestedupdatestopreventinfiniteloops.从它向我展示的代码片段来看,clear()函数似乎是这里的问题,但我认为我没有在rend

javascript - 在 componentWillUpdate 或 componentDidUpdate 中重复调用 setState?

我试图找出作为Prop传入的React组件中背景图像的方向。我首先创建一个图像对象并将其src设置为新图像:getImage(){constsrc=this.props.url;constimage=newImage();image.src=src;this.setState({height:image.height,width:image.width});}在使用高度和宽度更新状态后,我尝试在componentDidUpdate()中调用getOrientation():getOrientation(){const{height,width}=this.state;if(height

javascript - 如果连接到未更改的商店,React componentDidUpdate 方法不会在继承的 Prop 更改时触发

我想让我的组件知道是否已经加载了一些库。要知道从任何上下文我都将它连接到我商店的“库”reducer到我的组件。我还从调用组件的父级向它传递一个配置对象this.props.dataObject。像这样:classGoogleButtonextendsComponent{render(){if(this.props.libraries.google){return}else{returnnull}}componentDidUpdate(){gapi.interactivepost.render('sharePost',this.props.dataObject)}}functionma

javascript - 冒泡 componentWillUpdate 和 componentDidUpdate

我知道这不是惯用的React,但我正在开发一个React组件(反向ScrollView),它需要在渲染之前和渲染之后得到下游虚拟DOM更改的通知。这有点难以解释,所以我制作了一个起点为JSFiddle:https://jsfiddle.net/7hwtxdap/2/我的目标是让日志看起来像:Beginlogrenderrenderedsmallrenderedsmallrenderedsmallbeforeupdaterenderedbigafterupdatebeforeupdaterenderedbigafterupdatebeforeupdaterenderedbigafteru

javascript - React-Three-Renderer 引用在 componentDidUpdate 中不是当前的(包括 MVCE)

我正在使用react-three-renderer(npm,github)来构建带有three.js的场景.我遇到了一个归结为MVCE的问题。引用没有按我期望的顺序更新。首先,这里是要查看的主要代码:varReact=require('react');varReact3=require('react-three-renderer');varTHREE=require('three');varReactDOM=require('react-dom');classSimpleextendsReact.Component{constructor(props,context){super(pr

javascript - react ,使用 Refs 到 scrollIntoView() 在 componentDidUpdate() 中不起作用

我在我的应用程序中使用Redux,在一个组件内我想在商店发生变化时滚动到特定的div标签。我有Redux部分工作,所以它触发了componentDidUpdate()方法(我已经路由到这个组件View)。据我所知,问题是scrollIntoView()方法无法正常工作,因为componentDidUpdate()具有滚动到顶部覆盖scrollIntoView()的默认行为。为了解决这个问题,我将调用scrollIntoView()的函数包装在一个setTimeout中,以确保稍后发生。我想做的是调用preventDefault()或任何其他更优雅的解决方案,但我找不到从哪里获取触发“s

javascript - 为什么 componentDidUpdate() 会创建一个无限循环?

我已经存储了url和一个token在state在Parent零件。我正在传递url和一个token作为props来自parentComponent给childComponent.但是,如果父级中有一些事件Component,setState()被触发,结果,componentDidUpdate()child的Component被执行。作为componentDidUpdate()导致无限循环(因为它触发了子组件内的setState()),我已经放置了条件。但这并不能防止错误。子组件即DisplayRevenue如下:importReact,{Component}from'react';i

javascript - react Hook : What/Why `useEffect` ?

关于新提出的ReactEffectHook;EffectHook(useEffect())有哪些优点和用例?为什么它会更可取?它与componentDidMount/componentDidUpdate/componentWillUnmount(性能/可读性)有何不同?文档指出:Mutations,subscriptions,timers,logging,andothersideeffectsarenotallowedinsidethemainbodyofafunctioncomponent(referredtoasReact’srenderphase).但我认为将这些行为放在生命周期

javascript - componentWillReceiveProps 和 componentDidUpdate 无限循环

我试图在从子组件更改状态后更新状态但没有成功,每次我调用该函数时都会出现堆栈溢出,prop无限次调用该函数,但问题是,我真的需要更新这个状态,目前不知道如何解决这个问题。父级importReact,{PropTypes,Component}from'react';importCardfrom'./card/card.js';importstylefrom'./style.scss';classContainerextendsComponent{constructor(props){super(props);this.state={isFlipped:false,oneOpened:tr

componentdidmount和componentDidupdate错误:无法在调度中派遣

我有错误的InvariantViolation:Dispatch.dispatch(...):Cannotdispatchinthemiddleofadispatch.当使用2种生命周期的反应方法来调用API。componentDidMount(){constaction_id=this.context.router.params.action_idif(action_id){this.getMsg(action_id)}}componentDidUpdate(prevContext){constaction_id=this.context.router.params.action_idif(
12