Fixes according to James's review
This commit is contained in:
parent
5182f69477
commit
a4ed4af3cf
|
@ -4,6 +4,7 @@ import { useState, useEffect } from 'react'
|
||||||
import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants'
|
import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants'
|
||||||
|
|
||||||
type PropzProps = {
|
type PropzProps = {
|
||||||
|
// Params from the router query
|
||||||
params: any
|
params: any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,9 +13,7 @@ type PropzProps = {
|
||||||
// TODO: Could cache the result using stale-while-revalidate: https://swr.vercel.app/
|
// TODO: Could cache the result using stale-while-revalidate: https://swr.vercel.app/
|
||||||
export function usePropz(
|
export function usePropz(
|
||||||
initialProps: Object,
|
initialProps: Object,
|
||||||
getStaticPropz: (props: PropzProps) => Promise<any>,
|
getStaticPropz: (props: PropzProps) => Promise<any>
|
||||||
// Dynamic routes will need the query params from the router
|
|
||||||
needParams?: boolean
|
|
||||||
) {
|
) {
|
||||||
// If props were successfully server-side generated, just use those
|
// If props were successfully server-side generated, just use those
|
||||||
if (!_.isEmpty(initialProps)) {
|
if (!_.isEmpty(initialProps)) {
|
||||||
|
@ -27,10 +26,9 @@ export function usePropz(
|
||||||
|
|
||||||
const [propz, setPropz] = useState<any>(undefined)
|
const [propz, setPropz] = useState<any>(undefined)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (needParams && _.isEmpty(params)) {
|
if (router.isReady) {
|
||||||
return
|
getStaticPropz({ params }).then((result) => setPropz(result.props))
|
||||||
}
|
}
|
||||||
getStaticPropz({ params }).then((result) => setPropz(result.props))
|
|
||||||
}, [params])
|
}, [params])
|
||||||
return propz
|
return propz
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ export default function ContractPage(props: {
|
||||||
slug: string
|
slug: string
|
||||||
folds: Fold[]
|
folds: Fold[]
|
||||||
}) {
|
}) {
|
||||||
props = usePropz(props, getStaticPropz, true) ?? {
|
props = usePropz(props, getStaticPropz) ?? {
|
||||||
contract: null,
|
contract: null,
|
||||||
username: '',
|
username: '',
|
||||||
comments: [],
|
comments: [],
|
||||||
|
|
|
@ -118,7 +118,7 @@ export default function FoldPage(props: {
|
||||||
creatorScores: { [userId: string]: number }
|
creatorScores: { [userId: string]: number }
|
||||||
topCreators: User[]
|
topCreators: User[]
|
||||||
}) {
|
}) {
|
||||||
props = usePropz(props, getStaticPropz, true) ?? {
|
props = usePropz(props, getStaticPropz) ?? {
|
||||||
fold: null,
|
fold: null,
|
||||||
curator: null,
|
curator: null,
|
||||||
contracts: [],
|
contracts: [],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user