Created
January 7, 2024 13:45
-
-
Save akbarjondev/327de14c72f906495210fa264258371f to your computer and use it in GitHub Desktop.
Custom lazy function in React
This file contains hidden or 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
export const lazy = (componentFactoryPromise) => { | |
const componentPromise = componentFactoryPromise() | |
let Component | |
componentPromise.then(C => { | |
Component = C.default | |
}) | |
return (props) => { | |
if(!Component) { | |
throw componentPromise | |
} | |
return <Component {...props} /> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment