| Total Complexity | 3 |
| Complexity/F | 0 |
| Lines of Code | 30 |
| Function Count | 0 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import React, { useEffect } from 'react' |
||
| 2 | import { useRouter } from 'next/router' |
||
| 3 | import PostComponent from '~/modules/post/components/Post' |
||
| 4 | import Dispatcher from '~/modules/core/dispatch/Dispatcher' |
||
| 5 | import { getPostWithSlug } from '~/modules/post/state/action' |
||
| 6 | import { useState, useDispatch } from '~/modules/core/state/context' |
||
| 7 | |||
| 8 | const Post = () => { |
||
| 9 | const state = useState() |
||
| 10 | const dispatch = useDispatch() |
||
| 11 | const router = useRouter() |
||
| 12 | const { slug } = router.query |
||
| 13 | |||
| 14 | useEffect(() => { |
||
| 15 | if (!slug) return |
||
| 16 | Dispatcher(dispatch).send(getPostWithSlug, slug) |
||
| 17 | }, [router]) |
||
| 18 | |||
| 19 | const { loading, error, data } = state |
||
| 20 | return error ? ( |
||
| 21 | <div>{error.toString()}</div> |
||
| 22 | ) : loading ? ( |
||
| 23 | <div> </div> |
||
| 24 | ) : ( |
||
| 25 | <PostComponent data={data} /> |
||
| 26 | ) |
||
| 27 | } |
||
| 28 | |||
| 29 | export default Post |
||
| 30 |