Skip to content

Code Quality: Refactor all React class components to functional components using hooks #22890

Closed

Description

@youknowriad

The official recommendation for writing React components is as follows.

All components should be implemented as function components, using hooks for managing component lifecycle and state.

If you're a new/junior contributor looking to help with this refactoring, follow these steps:

  • Search for class components on the codebase (For example by searching extends Component
  • Pick a component to refactor.
  • Comment on this issue saying that you're working on the said component.

Note This is a tracking issue for the React components guidelines. This issue is tailored specifically for junior and new contributors. Experienced contributors shouldn't do big refactorings unless they update the code for another reason (bug fix, feature).

Activity

  1. added
    Good First Issue
    [Type] Code Quality
    [Type] Tracking Issue
    on Jun 4, 2020
  2. pkvillanueva commented on Jun 4, 2020

    @pkvillanueva
    Contributor

    👋 I'm working on TabPanel component.

  3. truchot commented on Jun 4, 2020

    @truchot
    Contributor

    I'm working on DatePicker component ;)

  4. cbravobernal commented on Jun 4, 2020

    @cbravobernal
    Contributor

    I'm working on Dashicon component :-)

  5. torounit commented on Jun 4, 2020

    @torounit
    Member

    I'm working on ImageSizeControl component.

  6. youknowriad commented on Jun 4, 2020

    @youknowriad
    ContributorAuthor

    @c4rl0sbr4v0 Actually the Dashicon component is a bit special, it's one that is generated on a separate repository and injected here as is (not edited manually), I'd recommend working on another component if possible.

  7. cbravobernal commented on Jun 4, 2020

    @cbravobernal
    Contributor

    Question about refactoring components: should we use function Name () {} or an arrow function -> const Name = () => {} ?

    In order to have all more or less the same structure :-)

  8. truchot commented on Jun 4, 2020

    @truchot
    Contributor

    Question about refactoring components: should we use function Name () {} or an arrow function -> const Name = () => {} ?

    In order to have all more or less the same structure :-)

    I use function Name() {} for components and arrow function inside. I don't know if I do well.

  9. pkvillanueva commented on Jun 4, 2020

    @pkvillanueva
    Contributor

    @c4rl0sbr4v0 I think both are fine to use.

  10. youknowriad commented on Jun 4, 2020

    @youknowriad
    ContributorAuthor

    We don't have a defined guideline, I think we prefer function Name in general but @truchot's way is a good middle ground too.

  11. cbravobernal commented on Jun 4, 2020

    @cbravobernal
    Contributor

    I took Dropdown, this is not an easy one 😆

  12. truchot commented on Jun 4, 2020

    @truchot
    Contributor

    Question about refactoring components: should we use function Name () {} or an arrow function -> const Name = () => {} ?

    In order to have all more or less the same structure :-)

    @c4rl0sbr4v0 : It seems named functions are more appreciated than arrow functions 😄
    I understand it's more convenient to debug.

  13. ellatrix commented on Jun 5, 2020

    @ellatrix
    Member

    It's especially good to refactor the blocks since that code is the most looked at and copied.

  14. 43 remaining items

  15. rushikeshmore commented on May 31, 2026

    @rushikeshmore
    Contributor

    Converted withFallbackStyles to a function component with hooks in #78837.

  16. sajjadfaraj-dev commented on Aug 3, 2026

    @sajjadfaraj-dev

    Hi! I would like to work on refactoring withFontSizes in packages/block-editor/src/components/font-sizes/with-font-sizes.js from its remaining class component to a function component using hooks, while preserving the existing HOC API and behavior.

    I will keep the change scoped to this component and add focused regression coverage for the derived font-size values and setters.

    I use AI assistance as part of my engineering workflow; I will review and validate the implementation myself and disclose the assistance in the PR according to the project guidelines.

  17. removed
    [Status] In Progress
    on Aug 13, 2026
  18. aadil42 commented on Aug 14, 2026

    @aadil42

    I'd like to refactor MediaUploadModalWrapper in packages/editor/src/hooks/media-upload.js from class component to a functional component.

    This component only uses state to track isOpen state which we can be refactor with simple useState

    I have added tests as well.

    Thank you.

  19. Mamaduka commented on Aug 18, 2026

    @Mamaduka
    Member

    Thanks everyone for contributing to this effort. The migration is mostly done. Only one or two items remain and they've PRs, just waiting for reviews.

    Search might show cases that don't need refactoring and class components are used either for testing purposes or for backward compatibility. Error boundaries also have to remain class components.

    I'm going to close this issue. If you have time please test/review linked open PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First Issue[Package] Components[Type] Code Quality[Type] Tracking Issue

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions