Skip to content

Commit

Permalink
feat(docz): use getInitialProps instead of getInitialData
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Feb 22, 2019
1 parent fbbd51c commit d4406e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions core/docz/src/components/AsyncComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isFn } from '../utils/helpers'

interface Props {
as: ComponentType<any>
getInitialData?: (props: any) => any
getInitialProps?: (props: any) => any
}

export const AsyncComponent: SFC<Props> = defaultProps => {
Expand All @@ -15,11 +15,11 @@ export const AsyncComponent: SFC<Props> = defaultProps => {
const [data, setData] = useState({})

useEffect(() => {
const { getInitialData } = defaultProps
const { getInitialProps } = defaultProps

if (getInitialData && isFn(getInitialData)) {
if (getInitialProps && isFn(getInitialProps)) {
setLoading(true)
getInitialData(defaultProps)
getInitialProps(defaultProps)
.then((data: any) => {
setLoading(false)
setError(null)
Expand All @@ -33,6 +33,6 @@ export const AsyncComponent: SFC<Props> = defaultProps => {
}
}, [])

const { as: Comp, getInitialData, ...props } = defaultProps
const { as: Comp, getInitialProps, ...props } = defaultProps
return <Comp {...props} data={{ ...data, loading, error }} />
}
4 changes: 2 additions & 2 deletions core/docz/src/components/AsyncRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { AsyncComponent } from './AsyncComponent'
export type Imports = Record<string, () => Promise<any>>
export const loadRoute = (path: string, imports: Imports) => {
return loadable(async () => {
const { default: Component, getInitialData } = await imports[path]()
const { default: Component, getInitialProps } = await imports[path]()
const ExportedComponent: SFC<any> = props => (
<AsyncComponent
{...props}
as={Component || 'div'}
getInitialData={getInitialData}
getInitialProps={getInitialProps}
/>
)

Expand Down

0 comments on commit d4406e0

Please sign in to comment.