美文网首页
react + vite 踩坑

react + vite 踩坑

作者: 黑色的浅蓝 | 来源:发表于2023-06-07 10:16 被阅读0次

一、useImperativeHandle 绑定的ref .current在某时变为null

// 每次都是从新生成 ref.current = null。 在生成 ref.current={x:1}
useImperativeHandle(ref, () => {
  return { x: 1 };
});
// 解决办法,取值可以用函数实现
useImperativeHandle(
  ref,
  () => {
    return {
      getX: () => 1,
    };
  },
  []
);

二 、在 index.d.ts文件中引用了其他文件:找不到模块“xx/index.d”或其相应的类型声明

  1. index.d.ts 的文件中引用了其他文件,需要在 同文件夹的index.tsx文件中添加导入 export * from "./index.d";

相关文章

网友评论

      本文标题:react + vite 踩坑

      本文链接:https://www.haomeiwen.com/subject/ncmnedtx.html