1

I have a class component where after updating state,I am calling a function immediately as a callback func in setState.

Code

this.setState(
      {
        selectedOption: resp?.vatTaxName,
        isUpdateVatTax: !!resp?.vatTaxName,
        vatTaxRate: resp?.vatTaxRate,
        vatTaxName: resp?.vatTaxName,
        vatTaxId: resp?.vatTaxId,
      },
      () => this.checkVatEnabled(this.state.selectedOption),
)

I want to use the same code in functional component,How I can achieve this?

Anurag Sharma
  • 301
  • 3
  • 18
  • Does this answer your question? [How to use \`setState\` callback on react hooks](https://stackoverflow.com/questions/56247433/how-to-use-setstate-callback-on-react-hooks) – Tushar Shahi Oct 17 '22 at 07:59
  • Does this answer your question? [React setState with callback in functional components](https://stackoverflow.com/questions/61840817/react-setstate-with-callback-in-functional-components) – jonrsharpe Oct 17 '22 at 08:00
  • I checked the example and what would the code look like? I get that with useEffect ,we can achieve this but I am not sure how to implement this. – Anurag Sharma Oct 17 '22 at 08:54

0 Answers0