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

[$250] Migrate Button.js to function component #16121

Closed
1 task
marcaaron opened this issue Mar 20, 2023 · 30 comments
Closed
1 task

[$250] Migrate Button.js to function component #16121

marcaaron opened this issue Mar 20, 2023 · 30 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering Improvement Item broken or needs improvement. Reviewing Has a PR in review

Comments

@marcaaron
Copy link
Contributor

Class Component Migration

Filenames

  • src/components/Button.js
    • type: React.Component
    • has state values: false
    • has refs: false
    • has context: false
    • lifecycle methods: componentDidMount,componentWillUnmount

Task

  • We currently have some class components in our codebase that we would like to refactor to a function component.
  • Here's a link with some general advice on how to refactor a class component to a function component: https://react.dev/reference/react/Component#alternatives
  • If you need additional guidance, please ask in #expensify-open-source
  • Test for any regressions and verify that there are no breaking changes
@marcaaron marcaaron added Engineering Improvement Item broken or needs improvement. labels Mar 20, 2023
@melvin-bot melvin-bot bot locked and limited conversation to collaborators Mar 20, 2023
@Expensify Expensify unlocked this conversation Mar 21, 2023
@marcaaron marcaaron changed the title [HOLD] Migrate Button.js to function component [HOLD][$250] Migrate Button.js to function component Apr 13, 2023
@kuluruvineeth

This comment was marked as spam.

@s-alves10
Copy link
Contributor

I'd love to work on this.

@Lai-Star
Copy link

Proposal

Hi, I'd like to finish this task.
Certainly, it's a good practice to refactor class components to function components using React Hooks as they make your code cleaner and easier to understand.
Let's assume your Button.js class component currently looks something like this:

jsx
Copy code
import React from 'react';

class Button extends React.Component {
componentDidMount() {
// Some code here
}

componentWillUnmount() {
// Some code here
}

render() {
return (
{this.props.children}
);
}
}

export default Button;
Following the advice from the React documentation you provided, the refactored functional component with hooks might look like this:

jsx
Copy code
import React, { useEffect } from 'react';

const Button = (props) => {
useEffect(() => {
// Equivalent to componentDidMount
// Some code here

return () => {
  // Equivalent to componentWillUnmount
  // Some code here
};

}, []); // The empty array causes this effect to only run once on mount and unmount

return (
{props.children}
);
};

export default Button;
In this refactored version, we use the useEffect hook. The function passed to useEffect will run after the render is committed to the screen (acting like componentDidMount). If you return a function from useEffect, React will run it when it is cleaning up the component (acting like componentWillUnmount).

Once you have made these changes, you should test the component thoroughly to ensure that no functionality was broken during the refactoring process. This could involve manual testing, or running an existing suite of automated tests if you have them.

@melvin-bot melvin-bot bot added the Daily KSv2 label Jun 15, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jun 19, 2023

Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@melvin-bot melvin-bot bot added the Overdue label Jun 19, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jun 21, 2023

Huh... This is 4 days overdue. Who can take care of this?

@melvin-bot
Copy link

melvin-bot bot commented Jun 23, 2023

6 days overdue. This is scarier than being forced to listen to Vogon poetry!

@melvin-bot
Copy link

melvin-bot bot commented Jun 27, 2023

10 days overdue. Is anyone even seeing these? Hello?

@melvin-bot
Copy link

melvin-bot bot commented Jun 29, 2023

12 days overdue. Walking. Toward. The. Light...

@melvin-bot melvin-bot bot added Weekly KSv2 and removed Daily KSv2 labels Jul 3, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 3, 2023

This issue has not been updated in over 14 days. eroding to Weekly issue.

@melvin-bot melvin-bot bot removed the Overdue label Jul 3, 2023
@vdem0115
Copy link

vdem0115 commented Jul 7, 2023

I'd like to work on this issue

@olexyt
Copy link
Contributor

olexyt commented Jul 7, 2023

I can work on this issue.

@rayane-djouah
Copy link
Contributor

I'd like to work on this issue

@ghost
Copy link

ghost commented Jul 11, 2023

Dibs

@melvin-bot melvin-bot bot added the Overdue label Jul 11, 2023
@mkhutornyi
Copy link
Contributor

I'd like to work on this.

@melvin-bot melvin-bot bot added Monthly KSv2 and removed Weekly KSv2 labels Jul 27, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 27, 2023

This issue has not been updated in over 15 days. eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

@melvin-bot melvin-bot bot removed the Overdue label Jul 27, 2023
@fabioh8010
Copy link
Contributor

@marcaaron Could you reopen this issue and assign to me please? It turns out that the file still exists and I need to migrate it to function component before migrating to TS. Thanks!

@marcaaron
Copy link
Contributor Author

Sounds good. Feel free to get me for the final merge!

@marcaaron marcaaron changed the title [HOLD][$250] Migrate Button.js to function component [$250] Migrate Button.js to function component Oct 24, 2023
@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Monthly KSv2 labels Oct 27, 2023
@fabioh8010
Copy link
Contributor

@marcaaron PR is now ready to review!

@melvin-bot melvin-bot bot added Monthly KSv2 and removed Weekly KSv2 labels Nov 20, 2023
Copy link

melvin-bot bot commented Nov 20, 2023

This issue has not been updated in over 15 days. @fabioh8010, @marcaaron eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

@parasharrajat
Copy link
Member

This needs a BZ member. Please assign me as C+ as well.

@marcaaron marcaaron added the Bug Something is broken. Auto assigns a BugZero manager. label Nov 21, 2023
Copy link

melvin-bot bot commented Nov 21, 2023

Triggered auto assignment to @dylanexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot melvin-bot bot added Daily KSv2 and removed Monthly KSv2 labels Nov 21, 2023

This comment was marked as off-topic.

@marcaaron
Copy link
Contributor Author

Thanks for catching that one @parasharrajat - sorry for the delay!

@marcaaron
Copy link
Contributor Author

@dylanexpensify this is not a bug - @parasharrajat just needs payment for the C+ review on the linked PR Thanks!

@dylanexpensify
Copy link
Contributor

Ahh apologies! Will get payment going!

@parasharrajat
Copy link
Member

It just needs a summary @dylanexpensify. Feel free to close it afterward. I will request later.

@dylanexpensify
Copy link
Contributor

dylanexpensify commented Nov 22, 2023

Payment summary:

Please request!

@parasharrajat
Copy link
Member

Payment requested as per #16121 (comment)

@JmillsExpensify
Copy link

$250 payment approved for @parasharrajat based on summary above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering Improvement Item broken or needs improvement. Reviewing Has a PR in review
Projects
None yet
Development

No branches or pull requests