Created
August 10, 2023 00:09
-
-
Save fernandocamargo/d0114fdd16b3f192c8490aad8119c674 to your computer and use it in GitHub Desktop.
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
import { Suspense, createElement, forwardRef, lazy } from 'react'; | |
import { css } from '@/tools/emotion'; | |
export const enhance = ([{ default: render }, { default: style }]) => { | |
const className = css({ name: render.hash }, style); | |
const component = (props, ref) => | |
createElement(forwardRef(Object.assign(render, { displayName: '✨' })), { | |
...props, | |
className, | |
ref | |
}); | |
return { default: forwardRef(Object.assign(component, { displayName: '💅' })) }; | |
}; | |
export const require = () => [import('./render'), import('./style')]; | |
export const load = () => Promise.all(require()).then(enhance); | |
export const Lazy = lazy(load); | |
export const fallback = 'Loading...'; | |
export const Core = (props, ref) => { | |
const children = createElement(Lazy, { ...props, ref }); | |
return createElement(Suspense, { fallback }, children); | |
}; | |
export default forwardRef(Core); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment