I've tried use dynamic import import()
in useEffect, like
// app.js
import {useEffect} from 'react'
function MyButton() {
const [Comp, setComp] = useState();
useEffect(() => {
// setComp(lazy(import("./test")))
import("./test").then((mod) => {
setComp(mod.default);
});
}, []);
return Comp ? <Comp /> : null;
}
// test.js
import { useMemo } from "react";
export default () => {
const title = useMemo(()=>'123',[])
return <div>{213}</div>;
};
but if the importee use react hooks internaly, the application will crash
because can't use hooks inside of useEffect
Top comments (0)