Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Use hooks instead of HoCs for EditorNotices #57772

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions packages/editor/src/components/editor-notices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
* WordPress dependencies
*/
import { NoticeList } from '@wordpress/components';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';

/**
* Internal dependencies
*/
import TemplateValidationNotice from '../template-validation-notice';

export function EditorNotices( { notices, onRemove } ) {
export function EditorNotices() {
const { notices } = useSelect(
( select ) => ( {
notices: select( noticesStore ).getNotices(),
} ),
[]
);
tyxla marked this conversation as resolved.
Show resolved Hide resolved
const { removeNotice } = useDispatch( noticesStore );
const dismissibleNotices = notices.filter(
( { isDismissible, type } ) => isDismissible && type === 'default'
);
Expand All @@ -28,19 +34,12 @@ export function EditorNotices( { notices, onRemove } ) {
<NoticeList
notices={ dismissibleNotices }
className="components-editor-notices__dismissible"
onRemove={ onRemove }
onRemove={ removeNotice }
>
<TemplateValidationNotice />
</NoticeList>
</>
);
}

export default compose( [
withSelect( ( select ) => ( {
notices: select( noticesStore ).getNotices(),
} ) ),
withDispatch( ( dispatch ) => ( {
onRemove: dispatch( noticesStore ).removeNotice,
} ) ),
] )( EditorNotices );
export default EditorNotices;
Loading