@@ -40,6 +40,7 @@ import useSaveHotKey from './hooks/useSaveHotkey';
40
40
import embedPlugin from '../../lib/remark/embedPlugin' ;
41
41
import { Helmet } from 'react-helmet-async' ;
42
42
import { toast } from 'react-toastify' ;
43
+ import { usePrevious } from 'react-use' ;
43
44
44
45
export type MarkdownEditorContainerProps = { } ;
45
46
@@ -122,6 +123,7 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
122
123
123
124
const [ upload , file ] = useUpload ( ) ;
124
125
const [ s3Upload , image ] = useS3Upload ( ) ;
126
+ const prevImage = usePrevious ( image ) ;
125
127
126
128
useEffect ( ( ) => {
127
129
if ( ! file ) return ;
@@ -131,10 +133,10 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
131
133
} , [ file , s3Upload ] ) ;
132
134
133
135
useEffect ( ( ) => {
134
- if ( ! thumbnail && image ) {
136
+ if ( image !== prevImage && ! thumbnail && image ) {
135
137
actionCreators . setThumbnail ( image ) ;
136
138
}
137
- } , [ actionCreators , image , thumbnail ] ) ;
139
+ } , [ actionCreators , image , prevImage , thumbnail ] ) ;
138
140
139
141
const onDragDropUpload = useCallback (
140
142
( file : File ) => {
@@ -252,7 +254,7 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
252
254
</ Helmet >
253
255
< MarkdownEditor
254
256
onUpload = { upload }
255
- lastUploadedImage = { publish ? null : image }
257
+ lastUploadedImage = { image }
256
258
initialBody = { initialBody }
257
259
title = { title }
258
260
markdown = { markdown }
0 commit comments