1- import React , { useState , useContext } from 'react'
1+ import React , { useState , useContext , useCallback } from 'react'
22
33import PostType from './../../types/Post'
44
@@ -30,8 +30,8 @@ interface MatchParam {
3030}
3131
3232const PostDetail : React . FC = ( ) => {
33- const [ error , setError ] = useState ( )
34- const [ isDeleteDialogOpen , setIsDeleteDialogOpen ] = useState ( false )
33+ const [ error , setError ] = useState < string > ( )
34+ const [ isDeleteDialogOpen , setIsDeleteDialogOpen ] = useState < boolean > ( false )
3535 const { match, history } = useReactRouter < MatchParam > ( )
3636 const client = useApolloClient ( )
3737 const meQuery = useContext ( MeQueryContext )
@@ -46,7 +46,7 @@ const PostDetail: React.FC = () => {
4646
4747 const deleteMutation = useMutation < DeleteMutationResponse > ( DELETE_MUTATION )
4848
49- const handlePublish = ( ) => {
49+ const handlePublish = useCallback ( ( ) => {
5050 if ( ! postQuery . data ) return
5151
5252 publishMutation ( {
@@ -60,9 +60,13 @@ const PostDetail: React.FC = () => {
6060 . catch ( ( e ) => {
6161 setError ( e . message )
6262 } )
63- }
63+ } , [ client , history , postQuery . data , publishMutation ] )
64+
65+ const handleDeleteDialogClose = useCallback ( ( ) => {
66+ setIsDeleteDialogOpen ( false )
67+ } , [ ] )
6468
65- const handleDelete = ( ) => {
69+ const handleDelete = useCallback ( ( ) => {
6670 if ( ! postQuery . data ) return
6771
6872 deleteMutation ( {
@@ -81,15 +85,11 @@ const PostDetail: React.FC = () => {
8185 . catch ( ( e ) => {
8286 setError ( e . message )
8387 } )
84- }
88+ } , [ client , deleteMutation , handleDeleteDialogClose , history , postQuery . data ] )
8589
86- const handleDeleteDialogClose = ( ) => {
87- setIsDeleteDialogOpen ( false )
88- }
89-
90- const handleDeleteDialogOpen = ( ) => {
90+ const handleDeleteDialogOpen = useCallback ( ( ) => {
9191 setIsDeleteDialogOpen ( true )
92- }
92+ } , [ ] )
9393
9494 if ( ! meQuery || ! meQuery . data || ! postQuery || ! postQuery . data )
9595 return < div > ERROR</ div >
0 commit comments