Skip to content

Commit

Permalink
fix(docz): remove null return on routes
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Mar 17, 2019
1 parent b856168 commit 5bbbbb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
28 changes: 14 additions & 14 deletions core/docz/src/components/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const goToHash = ({ location }: HistoryListenerParameter) => {
export const Routes: SFC<RoutesProps> = ({ imports }) => {
const components = useComponents()
const { entries } = useContext(doczState.context)
if (!entries || !components) return null

const NotFound: any = components.notFound
const Loading: any = components.loading
Expand All @@ -48,20 +47,21 @@ export const Routes: SFC<RoutesProps> = ({ imports }) => {
<React.Suspense fallback={<Loading />}>
<Router basepath={DOCZ_BASE_URL}>
<NotFound default />
{entries.map(({ key: path, value: entry }) => {
const props = { path, entries, components }
const component = loadRoute(path, imports)
{entries &&
entries.map(({ key: path, value: entry }) => {
const props = { path, entries, components }
const component = loadRoute(path, imports)

return (
<AsyncRoute
{...props}
entry={entry}
key={entry.id}
path={entry.route}
asyncComponent={component}
/>
)
})}
return (
<AsyncRoute
{...props}
entry={entry}
key={entry.id}
path={entry.route}
asyncComponent={component}
/>
)
})}
</Router>
</React.Suspense>
</LocationProvider>
Expand Down
3 changes: 1 addition & 2 deletions core/docz/src/hooks/useDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { doczState, Entry } from '../state'
import { compare } from '../utils/helpers'

export const useDocs = (): Entry[] | null => {
const { entries } = useContext(doczState.context)
if (!entries) return null
const { entries = [] } = useContext(doczState.context)
const arr = entries.map(({ value }) => value)
return sort(arr, (a: Entry, b: Entry) => compare(a.name, b.name))
}

0 comments on commit 5bbbbb3

Please sign in to comment.