Tencent / hel

A module federation SDK which is unrelated to tool chain for module consumer. 工具链无关的运行时模块联邦sdk.
https://tencent.github.io/hel/
Other
933 stars 79 forks source link

消费方报错 #7

Closed yoyooyooo closed 1 year ago

yoyooyooo commented 1 year ago
image
export default function HomePage() {
  useEffect(() => {
    bindReactRuntime({ React, ReactDOM });
  }, []);

  return (
    <div>
      <button
        onClick={() => {
          preFetchLib("hel-tpl-remote-react-comps-ts", {
            custom: { host: "http://localhost:3103", enable: !!location.port }
          })
            .then((res) => {
              console.log("远程包", res);
            })
            .catch(console.log);
        }}
      >
        test
      </button>
    </div>
  );
}

hel-tpl-remote-react-comps-ts 就是仓库里的模板,没做过改动

fantasticsoul commented 1 year ago

bindReactRuntime({ React, ReactDOM }) 需要第一时间调用,通常在入口文件第一行调用,见示例 https://codesandbox.io/s/demo-load-remote-react-comp-2bnpl0

image
fantasticsoul commented 1 year ago

我参考你这个例子改了一个,你可以看这个例子 https://codesandbox.io/s/naughty-kapitsa-e9ylji?file=/src/App.js

image
starsoul666 commented 1 year ago

我参考你这个例子改了一个,你可以看这个例子 https://codesandbox.io/s/naughty-kapitsa-e9ylji?file=/src/App.js

image

这种方式preFetchLib获取的组件怎么使用呀? 定义了一个state, 把res设置进去,使用的使用报错,不是一个组件 const [Component, setComponent] = useState();

setComponent(res)