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

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

Open
youknowriad opened this issue Jun 4, 2020 · 41 comments
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time [Package] Components /packages/components [Status] In Progress Tracking issues with work in progress [Type] Code Quality Issues or PRs that relate to code quality [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.

Comments

@youknowriad
Copy link
Contributor

youknowriad commented Jun 4, 2020

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

@youknowriad youknowriad added Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Code Quality Issues or PRs that relate to code quality [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues. labels Jun 4, 2020
@pkvillanueva
Copy link
Contributor

👋 I'm working on TabPanel component.

@truchot
Copy link
Contributor

truchot commented Jun 4, 2020

I'm working on DatePicker component ;)

@cbravobernal
Copy link
Contributor

I'm working on Dashicon component :-)

@torounit
Copy link
Member

torounit commented Jun 4, 2020

I'm working on ImageSizeControl component.

@youknowriad
Copy link
Contributor Author

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

@cbravobernal
Copy link
Contributor

cbravobernal commented Jun 4, 2020

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

@truchot
Copy link
Contributor

truchot commented Jun 4, 2020

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.

@pkvillanueva
Copy link
Contributor

@c4rl0sbr4v0 I think both are fine to use.

@youknowriad
Copy link
Contributor Author

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.

@cbravobernal
Copy link
Contributor

I took Dropdown, this is not an easy one 😆

@truchot
Copy link
Contributor

truchot commented Jun 4, 2020

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.

@ellatrix
Copy link
Member

ellatrix commented Jun 5, 2020

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

@pkvillanueva
Copy link
Contributor

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

@youknowriad
Copy link
Contributor Author

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

@jccit
Copy link

jccit commented Jun 10, 2020

I'm working on the PanelBody component

@oxyc
Copy link
Member

oxyc commented Jun 11, 2020

PR ready for Media & Text #23062 #23102

@pkvillanueva
Copy link
Contributor

PR for CalendarEdit #23072.

@grzim
Copy link
Contributor

grzim commented Nov 28, 2020

Tooltip done here #27353

@jhnstn
Copy link
Contributor

jhnstn commented Dec 7, 2020

I'm working on URLInput component.

@jhnstn jhnstn mentioned this issue Dec 7, 2020
6 tasks
@jhnstn
Copy link
Contributor

jhnstn commented Dec 10, 2020

I'm working on the Inserter component.

@ZebulanStanphill
Copy link
Member

I've done ServerSideRender in #28297. And as it turns out, @fabiankaegy was working on their own PR (#28289) simultaneously, which does the same thing, while also addressing #24519.

@chiilog
Copy link
Contributor

chiilog commented Jun 23, 2021

I'm working on FullscreenMode component.

@chiilog
Copy link
Contributor

chiilog commented Jun 23, 2021

@youknowriad I've done FullscreenMode in #32925 :)

@ciampo ciampo mentioned this issue Aug 25, 2021
31 tasks
@gziolo
Copy link
Member

gziolo commented Nov 24, 2021

It looks like there is still a lot of components to update:

Screenshot 2021-11-24 at 10 57 57

@youknowriad
Copy link
Contributor Author

@gziolo If I exclude native code, tests, documentation, error boundaries... I find 38 instances. It's a bit better :)

@amustaque97
Copy link
Member

I would like to refactor SlotComponent but not sure how to test it validate it to make sure if things are working correctly after refactoring! Can anyone please help with that?

@amustaque97
Copy link
Member

👋 I'm working on SuggestionsList component.

@amustaque97
Copy link
Member

Linked PR for ImportForm reusable component.

@louwie17
Copy link
Contributor

louwie17 commented Jun 8, 2023

I have a PR open to convert the EmbedPreview component -> #51325

@GP-Dan-Tovbein
Copy link

I'm working on the Media Upload Progress component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time [Package] Components /packages/components [Status] In Progress Tracking issues with work in progress [Type] Code Quality Issues or PRs that relate to code quality [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.
Projects
None yet
Development

No branches or pull requests