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

Fix: refactor pre publish panel to use function component instead of class #58441

Merged
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { useState } from '@wordpress/element';
import { compose, ifCondition } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';
import { PanelBody } from '@wordpress/components';
Expand Down Expand Up @@ -34,13 +34,8 @@ const TagsPanel = () => {
);
};

class MaybeTagsPanel extends Component {
constructor( props ) {
super( props );
this.state = {
hadTagsWhenOpeningThePanel: props.hasTags,
};
}
const MaybeTagsPanel = ( { hasTags } ) => {
const [ hadTagsWhenOpeningThePanel ] = useState( hasTags );

/*
* We only want to show the tag panel if the post didn't have
Expand All @@ -52,14 +47,12 @@ class MaybeTagsPanel extends Component {
* hiding this panel and keeping the user from adding
* more than one tag.
*/
render() {
if ( ! this.state.hadTagsWhenOpeningThePanel ) {
return <TagsPanel />;
}

return null;
if ( ! hadTagsWhenOpeningThePanel ) {
return <TagsPanel />;
}
}

return null;
};

export default compose(
withSelect( ( select ) => {
Expand Down
Loading