Skip to content

Commit

Permalink
support user custom loading component
Browse files Browse the repository at this point in the history
fix: #123
  • Loading branch information
csr632 committed Apr 10, 2023
1 parent 2963b93 commit 596ccf3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/theme-doc/src/ThemeConfig.doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ export interface ThemeConfig {
| FooterConfig
| ((ctx: ThemeContextValue) => FooterConfig | null | undefined)
/**
* View to be rendered when app in 404 state
* Component to be rendered when app in 404 state
* (url not matching any page)
*/
Component404?: React.ComponentType<React.PropsWithChildren<unknown>>
/**
* Component to be rendered when app is loading js bundle
*/
ComponentLoading?: React.ComponentType<React.PropsWithChildren<unknown>>
/**
* Wrap the App with custom Component.
* You can use `useThemeCtx()` in it to get context info
Expand Down
7 changes: 5 additions & 2 deletions packages/theme-doc/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function createTheme(

const location = useLocation()
useIsomorphicLayoutEffect(() => {
// scroll to anchor after page component loaded
// scroll to anchor link after page component loaded
if (loadState.type === 'loaded') {
if (location.hash) {
AnchorLink.scrollToAnchor(decodeURIComponent(location.hash.slice(1)))
Expand All @@ -40,7 +40,10 @@ export function createTheme(
}, [loadState, location.hash])

if (loadState.type === 'loading') {
return <AppLayout></AppLayout>
const ComponentLoading = themeConfig.ComponentLoading
return (
<AppLayout>{ComponentLoading ? <ComponentLoading /> : null}</AppLayout>
)
}

if (loadState.type === 'load-error') {
Expand Down

0 comments on commit 596ccf3

Please sign in to comment.