警告:可以在未数的组件上呼叫SetState(reactjs功能组件,kendoreact)

发布于 2025-01-18 23:02:21 字数 1679 浏览 1 评论 0原文

你能帮我解决这个警告吗?

在此处输入图像描述

我刚刚编写了一些“可能”与之相关的代码。我正在使用 KendoReact 图表组件,
在圆环图上,有一个功能可以在图表中间写入属性名称为“donutCenterRender”的内容。我用它来显示 api 上的总数据。一切都很顺利,但是我发现了警告,所以我尝试调查我的代码是否有问题

const { menuItem, chartApi, listApi } = props;
const [auctionData, setAuctionData] = useState(chartApi);
const [auctionId, setAuctionId] = useState(1);
const [auction, setAuction] = useState(auctionData[auctionId]);
const [Total, setTotal] = useState(0);

//... code

  useEffect(() => {
    const data = auction;
    let Total = 0;

    data.forEach(e => {
      Total += e.total;
    });
    setTotal(Total);
  }, []);

  const donutCenterRenderer = () => {
    return (
      <span>
        <h1>{Total}</h1> Total
      </span>
    );
  };

return (
//...code
      <div className="dash-chart d-flex flex-column bg-transparent">
        <Chart donutCenterRender={donutCenterRenderer}>
          <ChartArea background="transparent" />
          <ChartSeries>
            <ChartSeriesItem
              type="donut"
              data={auction}
              categoryField="status"
              field="total"
              holeSize={60}
              border={{ width: 20 }}
            />
          </ChartSeries>
          <ChartLegend
            position="bottom"
            margin={{ bottom: 20 }}
            orientation="vertical"
            labels={{
              margin: 5,
              content: e => `${e.text} \n ${e.value} Auctions`,
            }}
          />
        </Chart>
      </div>
//...code

谢谢

can you help me with this warning?

enter image description here

I just wrote a bit of code that "probably" relates to that. I'm using KendoReact Chart Component,
on the donut chart there is a feature to write something in the middle of the chart with the attribute name "donutCenterRender". I use it to display total data on api. Everything went smoothly, but I found the warning, so I tried to investigate my code if there is something wrong

const { menuItem, chartApi, listApi } = props;
const [auctionData, setAuctionData] = useState(chartApi);
const [auctionId, setAuctionId] = useState(1);
const [auction, setAuction] = useState(auctionData[auctionId]);
const [Total, setTotal] = useState(0);

//... code

  useEffect(() => {
    const data = auction;
    let Total = 0;

    data.forEach(e => {
      Total += e.total;
    });
    setTotal(Total);
  }, []);

  const donutCenterRenderer = () => {
    return (
      <span>
        <h1>{Total}</h1> Total
      </span>
    );
  };

return (
//...code
      <div className="dash-chart d-flex flex-column bg-transparent">
        <Chart donutCenterRender={donutCenterRenderer}>
          <ChartArea background="transparent" />
          <ChartSeries>
            <ChartSeriesItem
              type="donut"
              data={auction}
              categoryField="status"
              field="total"
              holeSize={60}
              border={{ width: 20 }}
            />
          </ChartSeries>
          <ChartLegend
            position="bottom"
            margin={{ bottom: 20 }}
            orientation="vertical"
            labels={{
              margin: 5,
              content: e => `${e.text} \n ${e.value} Auctions`,
            }}
          />
        </Chart>
      </div>
//...code

Thank you ????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文