小编Laï*_*Ken的帖子

Amcharts5 - 错误你不能在同一个 DOM 节点上有多个根 - React 17

我想在我的 React 应用程序中使用 amcharts5 创建图表。

我在我的应用程序组件中导入的组件中实例化 amcharts5 的根元素。我收到以下错误

You cannot have multiple Roots in the same DOM node
Run Code Online (Sandbox Code Playgroud)

这是我的版本:

"react": "^17.0.2"
"@amcharts/amcharts5": "^5.1.1"
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

import { useLayoutEffect } from 'react'
import * as am5 from '@amcharts/amcharts5'

export default function AmCharts5() {
  useLayoutEffect(() => {
    let root = am5.Root.new('chartdiv')

    // root.current = root
    // here is a second Error : Property 'current' does not exist on type 'Root'


    return () => {
      root.dispose()
    }
  }, [])

  return <div id="chartdiv" style={{ width: …
Run Code Online (Sandbox Code Playgroud)

amcharts reactjs amcharts5

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

amcharts ×1

amcharts5 ×1

reactjs ×1