Skip to content

Commit

Permalink
Preferences: Use hooks instead of HoC in 'EnablePublishSidebarOption' (
Browse files Browse the repository at this point in the history
…#67002)


Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
  • Loading branch information
3 people authored Nov 14, 2024
1 parent 4d0245c commit a120f10
Showing 1 changed file with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* WordPress dependencies
*/
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { privateApis as preferencesPrivateApis } from '@wordpress/preferences';

/**
Expand All @@ -13,16 +12,20 @@ import { store as editorStore } from '../../store';

const { PreferenceBaseOption } = unlock( preferencesPrivateApis );

export default compose(
withSelect( ( select ) => ( {
isChecked: select( editorStore ).isPublishSidebarEnabled(),
} ) ),
withDispatch( ( dispatch ) => {
const { enablePublishSidebar, disablePublishSidebar } =
dispatch( editorStore );
return {
onChange: ( isEnabled ) =>
isEnabled ? enablePublishSidebar() : disablePublishSidebar(),
};
} )
)( PreferenceBaseOption );
export default function EnablePublishSidebarOption( props ) {
const isChecked = useSelect( ( select ) => {
return select( editorStore ).isPublishSidebarEnabled();
}, [] );
const { enablePublishSidebar, disablePublishSidebar } =
useDispatch( editorStore );

return (
<PreferenceBaseOption
isChecked={ isChecked }
onChange={ ( isEnabled ) =>
isEnabled ? enablePublishSidebar() : disablePublishSidebar()
}
{ ...props }
/>
);
}

0 comments on commit a120f10

Please sign in to comment.