Skip to content

Commit

Permalink
Update method
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed May 1, 2022
1 parent cac83e2 commit 986ae57
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/editor/src/components/post-text-editor/index.js
Expand Up @@ -7,11 +7,12 @@ import Textarea from 'react-autosize-textarea';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useEffect, useState } from '@wordpress/element';
import { useState } from '@wordpress/element';
import { parse } from '@wordpress/blocks';
import { useDispatch, useSelect } from '@wordpress/data';
import { useInstanceId } from '@wordpress/compose';
import { VisuallyHidden } from '@wordpress/components';
import { useShortcut } from '@wordpress/keyboard-shortcuts';

/**
* Internal dependencies
Expand Down Expand Up @@ -65,15 +66,13 @@ export default function PostTextEditor() {
}
};

// Ensure changes aren't lost when the component unmounts
useEffect( () => {
return () => {
if ( isDirty ) {
const blocks = parse( value );
resetEditorBlocks( blocks );
}
};
}, [ isDirty, value ] );
// Ensure changes aren't lost when switching modes using shortcuts.
useShortcut( 'core/edit-post/toggle-mode', () => {
if ( isDirty ) {
const blocks = parse( value );
resetEditorBlocks( blocks );
}
} );

return (
<>
Expand Down

0 comments on commit 986ae57

Please sign in to comment.