Created
December 1, 2019 02:49
-
-
Save intojs/e7f28e4919d226d1c8865a0ae9c09804 to your computer and use it in GitHub Desktop.
Loan Calculator Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const LoanCalculator: FC = () => { | |
const [loanCalculation, setLoanCalculation] = useState<CalculateLoanRes | null>(null); | |
const onSubmit = async (values: LoanCalculatorFormValues) => { | |
const { | |
email, | |
loanAmount, | |
loanTerm, | |
lifeInsuranceOptIn, | |
} = values; | |
const calculation: CalculateLoanRes = await calculateLoan({ | |
emailAddress: email, | |
loanAmount, | |
loanTerm, | |
lifeInsuranceOptIn, | |
}); | |
setLoanCalculation(calculation); | |
}; | |
return ( | |
<> | |
<h1 className='mt-5'>Loan calculator</h1> | |
<hr/> | |
{ | |
loanCalculation | |
? <Calculation calculation={loanCalculation}/> | |
: <LoanCalculatorForm submit={onSubmit}/> | |
} | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment