You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
和 @antv/g6-extension-react 有相同的功能。
区别点在于利用 react portal 来渲染节点,而不是 ReactDOM.render。这样渲染出的节点都存在于一个 react 上下文中。
这样做的优势有很多,比如你可以直接在 graphReactNode 中直接调用 ReactRouter 的 api、或者访问你的全局状态;再比如你使用 antd 组件库,你可以全局配置主题色为红色,那么在 graphReactNode 中也会继承这些配置,主题色依旧是红色,如果使用 @antv/g6-extension-react 的话,主题色就会是 antd 的默认配置蓝色。
实现可以参考 https://github.com/guanriyue/antv-patch/blob/main/packages/g6-react-portal/src/index.tsx。
因为使用了 useSyncExternalStore api,所以需要 react 18 以上;支持 react 16、17 的话,需要使用 https://www.npmjs.com/package/use-sync-external-store。
demo 还没编写,可以参考测试用例里面的,在 JSX 中提供一个
<G6ReactNodeProvider graph={graph} />节点即可Beta Was this translation helpful? Give feedback.
All reactions