Created
September 25, 2022 09:14
-
-
Save multivoltage/c223278303737e5a317eda9710d355c2 to your computer and use it in GitHub Desktop.
strange solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// App.tsx | |
function App(){ | |
return <> | |
{false && <MyComp />} | |
</> | |
} | |
// MyComp.tsx | |
// myModule.js is a normal npm package | |
function MyComp(){ | |
const [mounted,setMounted] = useState(false) | |
const ref = useRef<any>() | |
useEffect(() => { | |
import("myModule.js").then(myModule){ | |
const { Pippo, Pluto } = myModule | |
Pippo.init(Pluto) | |
ref.current = Pluto | |
setMounted(true) | |
} | |
},[]) | |
if(!mounted) | |
return <span/> | |
return <ref.current optitions={...}/> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment