Why this const handleObligation = (obligationName : number) =>{…
- User
Why this const handleObligation = (obligationName : number) =>{
codesetIncome(obligationName); setTaxesForm(prev => {return ({...taxesForm, healthRyc: ZusZdrowotnyRyczalt12(), healthRycLinear: ZusZdrowotnyLiniowy19(), healthRycCommon: ZusZdrowotnyOgolny(), pensionContributions: (4161 * 0.1952), pensionRentalContributions: (4161 * 0.08), sicknessContributions: (4161 * 0.0245), accidentPremiums: (4161 * 0.0167), solidariyPremiums: (4161 * 0.0245) })}); //ZusZdrowotnyRyczalt12(); //ZusZdrowotnyLiniowy19(); //ZusZdrowotnyOgolny(); // Pension contributions: PLN 210.82 (19.52% of PLN 1080) Pension // contributions: PLN 86.40 (8% of 1080zl) Sickness contributions: PLN 26.46 // (2.45% of 1080zl) Accident premiums: PLN 18.04 (1.67% of 1080zl) // setPensionContributions(4161 * 0.1952); setPensionRentalContributions(4161 * // 0.08); setSicknessContributions(4161 * 0.0245); setAccidentPremiums(4161 * // 0.0167); setSolidariyPremiums(4161 * 0.0245); zlicz zusy zdrowotne var summary = taxesForm.pensionContributions + taxesForm.pensionRentalContributions + taxesForm.accidentPremiums + taxesForm.solidariyPremiums; if (isSicknessContributionsCalculated) summary = taxesForm.sicknessContributions; //setZushealthRycSummary(healthRyc + summary); //setZushealth19Summary(healthRycLinear + summary); //setZushealthCommonSummary(healthRycCommon + summary); setTaxesForm(prev =>{return{...taxesForm, zushealth19Summary: taxesForm.healthRyc + summary, zushealthCommonSummary: taxesForm.healthRycLinear + summary, zushealthRycSummary: taxesForm.healthRycCommon + summary }}); console.log('taxesForm ', taxesForm); } does not update taxesForm object? - Assistant
The issue is that you are using the previous state value of taxesForm when updating its properties inside setTaxesForm. This can lead to unexpected results as React batches multiple state updates together. To fix this issue, you need to use the updater function syntax of setTaxesForm, which provides you the latest state value.
Modify your code as follows:
javascript - User
we sometimes we use in react import with braces and sometimes we are without braces?
- Assistant
In React, the use of braces '{}' after the import keyword depends on the named exports of the module you are importing.
When importing a module that has a default export, you use the import statement without braces. For example:
javascriptimport SomeComponent from "./SomeComponent";Here,
SomeComponentrefers to the default export of the "./SomeComponent" module.When importing a module that has named exports (multiple exports named in the module), you use the import statement with braces. For example:
javascriptimport { Component1, Component2 } from "./SomeModule";Here,
Component1andComponent2refer to the named exports of the "./SomeModule" module.You can also use a combination of default and named exports in a single import statement. For example:
javascriptimport SomeComponent, { Component1, Component2 } from "./SomeModule"; - User
could you give me example of usage of each hook in react?
- Assistant
Certainly! Here are examples of usage for some commonly used React hooks:
- useState: to manage state in a functional component.
javascript