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

Created on 4 Jun 2020  路  28Comments  路  Source: WordPress/gutenberg

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).

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

Most helpful comment

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

All 28 comments

馃憢 I'm working on TabPanel component.

I'm working on DatePicker component ;)

I'm working on Dashicon component :-)

I'm working on ImageSizeControl component.

@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.

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 :-)

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.

@c4rl0sbr4v0 I think both are fine to use.

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.

I took Dropdown, this is not an easy one 馃槅

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.

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

If I work on refactoring the ColorPicker component, should I include its sub-components Alpha, Hue, Inputs, and Saturation?

@pkvillanueva not necessarily, you can do one by one.

I'm working on the PanelBody component

PR for CalendarEdit #23072.

PR for ToggleControl #23116
PR for Dropdown #23142

I'm working on Tag Cloud block.

I'm going to tackle Latest Comments block next. 馃憤

I'm tackling the Disabled component

I am working on the URLPopover component

I'll tackle <BlockInvalidWarning> 馃挭

I'll tackle <TimePicker> next 馃晲

I'm working on <BlockMover>!

I will be working on the GalleryImage component

I'm working on the ColorPicker component.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cr101 picture cr101  路  3Comments

maddisondesigns picture maddisondesigns  路  3Comments

mhenrylucero picture mhenrylucero  路  3Comments

davidsword picture davidsword  路  3Comments

youknowriad picture youknowriad  路  3Comments