Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editor: Use hooks instead of HoCs in 'PostSticky' components (#54949)
- Loading branch information
Showing
3 changed files
with
51 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { compose } from '@wordpress/compose'; | ||
import { withSelect } from '@wordpress/data'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editorStore } from '../../store'; | ||
|
||
export function PostStickyCheck( { hasStickyAction, postType, children } ) { | ||
export default function PostStickyCheck( { children } ) { | ||
const { hasStickyAction, postType } = useSelect( ( select ) => { | ||
const post = select( editorStore ).getCurrentPost(); | ||
return { | ||
hasStickyAction: post._links?.[ 'wp:action-sticky' ] ?? false, | ||
postType: select( editorStore ).getCurrentPostType(), | ||
}; | ||
}, [] ); | ||
|
||
if ( postType !== 'post' || ! hasStickyAction ) { | ||
return null; | ||
} | ||
|
||
return children; | ||
} | ||
|
||
export default compose( [ | ||
withSelect( ( select ) => { | ||
const post = select( editorStore ).getCurrentPost(); | ||
return { | ||
hasStickyAction: post._links?.[ 'wp:action-sticky' ] ?? false, | ||
postType: select( editorStore ).getCurrentPostType(), | ||
}; | ||
} ), | ||
] )( PostStickyCheck ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters