Download wp-calypso/client/components/async-load/index.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 794 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/async-load/index.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/components/async-load/index.tsx
-
curl -L -o index.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/async-load/index.tsx
794 Bytes
| import { lazy, useMemo, Suspense, type ComponentType, type ReactNode } from 'react'; | |
| import './style.scss'; | |
| const DEFAULT_PLACEHOLDER = <div className="async-load__placeholder" />; | |
| type AsyncLoadProps = { | |
| placeholder?: ReactNode; | |
| require: string; | |
| [ key: string ]: unknown; | |
| }; | |
| type RequireCallback = () => Promise< { default: ComponentType } >; | |
| export default function AsyncLoad( { | |
| placeholder = DEFAULT_PLACEHOLDER, | |
| require, | |
| ...props | |
| }: AsyncLoadProps ) { | |
| const Component = useMemo( () => { | |
| // The string is transformed to a function by the `wpcalypso-async` Babel transform | |
| const requireCb = require as unknown as RequireCallback; | |
| return lazy( requireCb ); | |
| }, [ require ] ); | |
| return ( | |
| <Suspense fallback={ placeholder }> | |
| <Component { ...props } /> | |
| </Suspense> | |
| ); | |
| } | |