Skip to content

Commit

Permalink
Merge pull request #89 from stack-wuh/feat-performance
Browse files Browse the repository at this point in the history
Feat performance
  • Loading branch information
stack-wuh committed Oct 30, 2022
2 parents 668e778 + 525e543 commit a868944
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions pages/post/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import withLayout from '@/layout/layout'

function useData(id: string | string[] | undefined) {
const {data, error} = useRequest(params => {
return fetcher(`${API_ARTICLE_ITEM}${params.id}`)
return fetcher(`${API_ARTICLE_ITEM}${params.id}`)
}, {
defaultParams: [{ id }],
cacheKey: API_ARTICLE_ITEM
cacheKey: API_ARTICLE_ITEM,
})

return {
Expand All @@ -31,16 +31,33 @@ function useData(id: string | string[] | undefined) {

const Detail: React.FC<{}> = () => {
const router = useRouter()
const { data, error } = useData(router.query.id)
const [externalUrls, setExternalUrls] = React.useState({
hljs: '',
hlmjs: '',
github: ''
})
/**
* !FIXED 刷新页面 router.query.id 会出现一个空对象
*/
if (!router.query.id) return <Empty.Loading></Empty.Loading>

useExternal('https://src.wuh.site/scripts/highlight.min.js', { type: 'js' })
useExternal('https://src.wuh.site/scripts/highlight.js', { type: 'js' })
useExternal('https://src.wuh.site/stylesheet/github.min.css', { type: 'css' })
const { data, error } = useData(router.query.id)

useExternal(externalUrls.hljs, { type: 'js' })
useExternal(externalUrls.hlmjs, { type: 'js' })
useExternal(externalUrls.github, { type: 'css' })

if (error) return <div className="error">ERROR</div>
if (!data) return <Empty.Loading />

React.useEffect(() => {
setExternalUrls({
hljs: 'https://src.wuh.site/scripts/highlight.min.js',
hlmjs: 'https://src.wuh.site/scripts/highlight.js',
github: 'https://src.wuh.site/stylesheet/github.min.css'
})
}, [])


return (
<div className="ww_detail">
Expand Down

1 comment on commit a868944

@vercel
Copy link

@vercel vercel bot commented on a868944 Oct 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.