gloriasoft / veaury

Use React in Vue3 and Vue3 in React, And as perfect as possible!
MIT License
1.31k stars 83 forks source link

vue中使用react hooks组件需要什么配置吗,直接使用applyPureReactInVue报错了 #86

Closed HandsomeBrother closed 1 year ago

HandsomeBrother commented 1 year ago

vue中使用react hooks组件需要什么配置吗,直接使用applyPureReactInVue报错了

image

代码

// react
import React, {  useState } from 'react';
 export function PieChartPanel(props: any) {
  const [width, setWidth] = useState(0)
  setWidth(100)
  console.log('pie props', props, width)
  return (
    <div>demo</div>
  );
}

// use in vue

  import { applyPureReactInVue } from 'veaury'
  const PieChartVue = applyPureReactInVue(PieChartPanel)
  console.log('props.plugin.panel',  PieChartPanel)
image
devilwjp commented 1 year ago

@HandsomeBrother 请提供一个可以复现问题的项目

HandsomeBrother commented 1 year ago

@devilwjp https://github.com/HandsomeBrother/veaury-demo 1: npm i 2: npm run build 3: cd hello-world 4: npm i 5: npm run serve 6: open console

devilwjp commented 1 year ago

@HandsomeBrother image 你的项目我跑过了,你的react组件把整个react的包也打进去了,然后引入vue项目时,veaury又引了react,产生了react多例,就会出现这个警告 正确的做法,react组件打包之后,不应该把react也打进去

要确保hooks可以正常的使用,整个项目中只能存在唯一的一个react单例,这个是react的规范,你的这个react组件,即便被其他react项目使用,也会报这个警告的

HandsomeBrother commented 1 year ago

感谢,我完善了一下demo,通过npm包提取veaury apply方法场景的webpack相关配置,https://github.com/HandsomeBrother/veaury-demo 可供遇到相同问题的同学参考