Fixes according to James's review

This commit is contained in:
Austin Chen 2022-03-08 18:39:08 -08:00
parent 5182f69477
commit a4ed4af3cf
3 changed files with 6 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import { useState, useEffect } from 'react'
import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants'
type PropzProps = {
// Params from the router query
params: any
}
@ -12,9 +13,7 @@ type PropzProps = {
// TODO: Could cache the result using stale-while-revalidate: https://swr.vercel.app/
export function usePropz(
initialProps: Object,
getStaticPropz: (props: PropzProps) => Promise<any>,
// Dynamic routes will need the query params from the router
needParams?: boolean
getStaticPropz: (props: PropzProps) => Promise<any>
) {
// If props were successfully server-side generated, just use those
if (!_.isEmpty(initialProps)) {
@ -27,10 +26,9 @@ export function usePropz(
const [propz, setPropz] = useState<any>(undefined)
useEffect(() => {
if (needParams && _.isEmpty(params)) {
return
if (router.isReady) {
getStaticPropz({ params }).then((result) => setPropz(result.props))
}
getStaticPropz({ params }).then((result) => setPropz(result.props))
}, [params])
return propz
}

View File

@ -79,7 +79,7 @@ export default function ContractPage(props: {
slug: string
folds: Fold[]
}) {
props = usePropz(props, getStaticPropz, true) ?? {
props = usePropz(props, getStaticPropz) ?? {
contract: null,
username: '',
comments: [],

View File

@ -118,7 +118,7 @@ export default function FoldPage(props: {
creatorScores: { [userId: string]: number }
topCreators: User[]
}) {
props = usePropz(props, getStaticPropz, true) ?? {
props = usePropz(props, getStaticPropz) ?? {
fold: null,
curator: null,
contracts: [],