diff --git a/packages/edit-post/src/components/preferences-modal/enable-panel.js b/packages/edit-post/src/components/preferences-modal/enable-panel.js index d698cdc360cae2..9053b74a695d6d 100644 --- a/packages/edit-post/src/components/preferences-modal/enable-panel.js +++ b/packages/edit-post/src/components/preferences-modal/enable-panel.js @@ -1,8 +1,7 @@ /** * WordPress dependencies */ -import { compose, ifCondition } from '@wordpress/compose'; -import { withSelect, withDispatch } from '@wordpress/data'; +import { useDispatch, useSelect } from '@wordpress/data'; import { store as editorStore } from '@wordpress/editor'; import { privateApis as preferencesPrivateApis } from '@wordpress/preferences'; @@ -13,18 +12,29 @@ import { unlock } from '../../lock-unlock'; const { PreferenceBaseOption } = unlock( preferencesPrivateApis ); -export default compose( - withSelect( ( select, { panelName } ) => { - const { isEditorPanelEnabled, isEditorPanelRemoved } = - select( editorStore ); - return { - isRemoved: isEditorPanelRemoved( panelName ), - isChecked: isEditorPanelEnabled( panelName ), - }; - } ), - ifCondition( ( { isRemoved } ) => ! isRemoved ), - withDispatch( ( dispatch, { panelName } ) => ( { - onChange: () => - dispatch( editorStore ).toggleEditorPanelEnabled( panelName ), - } ) ) -)( PreferenceBaseOption ); +export default function EnablePanelOption( props ) { + const { toggleEditorPanelEnabled } = useDispatch( editorStore ); + const { isChecked, isRemoved } = useSelect( + ( select ) => { + const { isEditorPanelEnabled, isEditorPanelRemoved } = + select( editorStore ); + return { + isChecked: isEditorPanelEnabled( props.panelName ), + isRemoved: isEditorPanelRemoved( props.panelName ), + }; + }, + [ props.panelName ] + ); + + if ( isRemoved ) { + return null; + } + + return ( + toggleEditorPanelEnabled( props.panelName ) } + { ...props } + /> + ); +} diff --git a/packages/editor/src/components/preferences-modal/enable-panel.js b/packages/editor/src/components/preferences-modal/enable-panel.js index 66c91409434415..2e1839d8fe2547 100644 --- a/packages/editor/src/components/preferences-modal/enable-panel.js +++ b/packages/editor/src/components/preferences-modal/enable-panel.js @@ -1,8 +1,7 @@ /** * WordPress dependencies */ -import { compose, ifCondition } from '@wordpress/compose'; -import { withSelect, withDispatch } from '@wordpress/data'; +import { useDispatch, useSelect } from '@wordpress/data'; import { privateApis as preferencesPrivateApis } from '@wordpress/preferences'; /** @@ -13,18 +12,29 @@ import { store as editorStore } from '../../store'; const { PreferenceBaseOption } = unlock( preferencesPrivateApis ); -export default compose( - withSelect( ( select, { panelName } ) => { - const { isEditorPanelEnabled, isEditorPanelRemoved } = - select( editorStore ); - return { - isRemoved: isEditorPanelRemoved( panelName ), - isChecked: isEditorPanelEnabled( panelName ), - }; - } ), - ifCondition( ( { isRemoved } ) => ! isRemoved ), - withDispatch( ( dispatch, { panelName } ) => ( { - onChange: () => - dispatch( editorStore ).toggleEditorPanelEnabled( panelName ), - } ) ) -)( PreferenceBaseOption ); +export default function EnablePanelOption( props ) { + const { toggleEditorPanelEnabled } = useDispatch( editorStore ); + const { isChecked, isRemoved } = useSelect( + ( select ) => { + const { isEditorPanelEnabled, isEditorPanelRemoved } = + select( editorStore ); + return { + isChecked: isEditorPanelEnabled( props.panelName ), + isRemoved: isEditorPanelRemoved( props.panelName ), + }; + }, + [ props.panelName ] + ); + + if ( isRemoved ) { + return null; + } + + return ( + toggleEditorPanelEnabled( props.panelName ) } + { ...props } + /> + ); +}