shenjunru / react-fiber-keep-alive

A component that maintains component state and avoids repeated re-rendering.
MIT License
60 stars 1 forks source link

如果 KeepAlive 包裹了 Echarts 组件,二次利用 cache 展示时会报错 #2

Closed Leecason closed 1 year ago

Leecason commented 2 years ago
image

"react-fiber-keep-alive": "^0.6.3", "react": "18.2.0", "react-dom": "18.2.0", "echarts": "5.0.2", "echarts-for-react": "3.0.1",

shenjunru commented 2 years ago

<ReactLightchartsCore> 是你自己的组件吗? 有没有完整的例子可以提供

shenjunru commented 2 years ago

我创建了一个 echarts-for-react 官方的 demo https://codesandbox.io/s/lucid-wilson-6hh9pn 没有看见你的报错

Leecason commented 2 years ago

<ReactLightchartsCore> 是你自己的组件吗? 有没有完整的例子可以提供

应该是 import ReactECharts from "echarts-for-react"; 这个组件

Leecason commented 2 years ago

我创建了一个 echarts-for-react 官方的 demo https://codesandbox.io/s/lucid-wilson-6hh9pn 没有看见你的报错

用法有点不一样,我这边 <KeepAlive> 是当组件使用的,另外 <KeepAlive.Provider> 包裹的必须是最外层的 <App> 吗,我包裹的是一个子组件。

shenjunru commented 2 years ago

<KeepAlive.Provider> 不一定在最外层。 但是一般能拿到 container element 的都在入口处。 同时如果 <KeepAlive.Provider> 也卸载了,那所有的cache 也都没有了。

Leecason commented 2 years ago

<KeepAlive.Provider> 不一定在最外层。 但是一般能拿到 container element 的都在入口处。 同时如果 <KeepAlive.Provider> 也卸载了,那所有的cache 也都没有了。

请问一下有试过把 KeepAlive 当组件用的例子吗

shenjunru commented 2 years ago

https://codesandbox.io/s/keep-alive-react-router-example-hfbbi7 其中 Page B (Keep-Alive Items) 就是一个页面中有多个 <KeepAlive>

shenjunru commented 2 years ago

介于你只提供了一张报错截图,我在 echartsecharts-for-react 的源码中也未发现图中的函数 如果方便的话,还请创建一个demo,我才能更明确的帮到你 @Leecason