Skip to content

Conversation

bc-peng
Copy link
Contributor

@bc-peng bc-peng commented Aug 25, 2025

What/Why?

Convert class component CreditCardPaymentMethodComponent into function component.

Replacing class components with function components eliminates the need for traditional lifecycle methods and enables full adoption of React 18 features like hooks and concurrent rendering.

This modernization aligns with React’s roadmap and ensures greater compatibility with future updates.

Rollout/Rollback

Revert.

Testing

CI.

@bc-peng bc-peng requested review from a team as code owners August 25, 2025 04:50

private getCreditCardPaymentMethodDerivedProps(): CreditCardPaymentMethodDerivedProps {
const { checkoutService, checkoutState, isUsingMultiShipping = false, method } = this.props;
useEffect(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve used three separate useEffect() hooks here, each handling a different existing concern componentDidMount, componentDidUpdate, and componentWillUnmount.

Merging them into a single useEffect() would blur the distinction between dependencies and lifecycle behaviors.

However, I’m happy to merge them if we think that’s prefered. ⏩️

}
};

void deInit();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created init(), reInit() and deInit() inside hooks.
Using explicit names makes their purpose clearer.
We may need to align on a consistent naming for these methods. ⏩️

@bc-peng bc-peng force-pushed the CreditCardPaymentMethodComponent branch 2 times, most recently from dc3c6c8 to 1d46946 Compare August 25, 2025 05:47
@bc-peng bc-peng force-pushed the CreditCardPaymentMethodComponent branch from 1d46946 to ebb9996 Compare August 25, 2025 05:55
}, [method, selectedInstrumentId, isAddingNewCard]);

useEffect(() => {
return () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a return from the effect that initialises the component?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I have combined both hooks into one useEffect().

@bc-peng bc-peng merged commit c768ce1 into master Aug 27, 2025
11 checks passed
@bc-peng bc-peng deleted the CreditCardPaymentMethodComponent branch August 27, 2025 00:02
@bc-launchbay
Copy link

checkout-js deployed to Integration US
success 20250827002601 by Launchbay

@bc-launchbay
Copy link

checkout-js deployed to Staging US
success 20250827002601 by Launchbay

@bc-launchbay
Copy link

checkout-js deployed to Production US
success 20250827002601 promoted by https://launchbay.bigcommerce.net/projects/535/releases/262379 being deployed. Deployed by Launchbay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants