简体   繁体   English

使用 Grommet Chart 组件时超过最大更新深度

[英]Maximum update depth exceeded React when using Grommet Chart component

I am getting the following error我收到以下错误

Uncaught Error: Maximum update depth exceeded.未捕获的错误:超过最大更新深度。 This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate.当组件在 componentWillUpdate 或 componentDidUpdate 中重复调用 setState 时,可能会发生这种情况。 React limits the number of nested updates to prevent infinite loops. React 限制了嵌套更新的数量以防止无限循环。

Followed by:其次是:

The above error occurred in the "Chart" component上述错误发生在“图表”组件中

my only use of the Chart component (which is from the grommet compontent lib) comes from this bit of code:我唯一使用的 Chart 组件(来自 grommet 组件库)来自这段代码:

 import {Chart} from 'grommet'; const WaveForm = (props:any):JSX.Element => { const size= props.waveForm.length const color = props.isRecording?"recording":props.isPrimed?"primed":"brand"; return ( <Chart bounds={[[0,Math.max(1000,size)], [-25,25]]} values= {props.waveForm.map((e:number,i:number) => ({value:[i, e, -e]}))} size={{"width": "fill",height:"75%"}} round={true} color={color} thickness="hair" /> ); } export default WaveForm;

I cannot for the life of me see why this is causing endless re-renders.我一生都无法理解为什么这会导致无休止的重新渲染。 Any help would be greatly appreciated.任何帮助将不胜感激。

The issue seemed to be due to an issue with the Grommet Chart handles 'fill'.该问题似乎是由于索环图表手柄“填充”的问题。 Changing改变

size={{"width": "fill",height:"75%"}}

to

size={{"width": "100%",height:"75%"}}

fixed the issue解决了这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM