6352257dd3
Since `next/dynamic` has client hooks that not compatible with server components, and app renderer doesn't provide context (such as `LoadableContext`) for it to use. Previously we provided a simple replacement using `React.lazy` for `next/dynamic` if you want to use it in appDir. This PR always alias it to the `React.lazy ` implementation for appDir so that user won't need to worry about the dynamic options. They can only use `dynamic()` without 2nd options arg ```js import dynamic from 'next/dynamic' const Dynamic = dynamic(() => import('./dynamic-component')) ```
19 lines
414 B
TypeScript
19 lines
414 B
TypeScript
import React from 'react'
|
|
|
|
export type LoaderComponent<P = {}> = Promise<{
|
|
default: React.ComponentType<P>
|
|
}>
|
|
|
|
export type Loader<P = {}> = () => LoaderComponent<P>
|
|
|
|
export type DynamicOptions<P = {}> = {
|
|
loader?: Loader<P>
|
|
}
|
|
|
|
export type LoadableComponent<P = {}> = React.ComponentType<P>
|
|
|
|
export default function dynamic<P = {}>(
|
|
loader: Loader<P>
|
|
): React.ComponentType<P> {
|
|
return React.lazy(loader)
|
|
}
|