Skip to content

Commit

Permalink
fix: Remove deprecated ref in Formik_v2.x.x
Browse files Browse the repository at this point in the history
  • Loading branch information
marslanabdulrauf committed Dec 27, 2024
1 parent 33a4e0d commit a269500
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions static/js/components/forms/B2BPurchaseForm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import React from "react";
import React, { useEffect } from "react";
import * as yup from "yup";
import { ErrorMessage, Field, Formik, Form } from "formik";
import Decimal from "decimal.js-light";
Expand Down Expand Up @@ -53,24 +53,6 @@ export const validate = (values: Object) => {
};

class B2BPurchaseForm extends React.Component<Props> {
formikRef = React.createRef<Formik>();

componentDidMount() {
// on page load apply the coupon code provided in the URL query paramater
const formikRef = this.formikRef;
if (formikRef) {
const formikRefObj = formikRef.current;
if (formikRefObj && formikRefObj.state.values.coupon) {
this.applyCoupon(
formikRefObj.state.values,
formikRefObj.setFieldError,
formikRefObj.setFieldTouched,
null,
);
}
}
}

applyCoupon = curry(
async (
values: Object,
Expand Down Expand Up @@ -271,9 +253,21 @@ class B2BPurchaseForm extends React.Component<Props> {
}}
validationSchema={emailValidation}
validate={validate}
render={this.renderForm}
ref={this.formikRef}
/>
>
{(formikProps) => {
useEffect(() => {
if (formikProps.values.coupon) {
this.applyCoupon(
formikProps.values,
formikProps.setFieldError,
formikProps.setFieldTouched,
null,
);
}
}, []);
return this.renderForm(formikProps);
}}
</Formik>
);
}
}
Expand Down

0 comments on commit a269500

Please sign in to comment.