React Project Tutorial – Build Mortgage Calculator App

Web Development

Learn React by creating a financial application what will calculate the mortgage using React useState hook.

About this project

In todays project you will learn how to create a mortgage calculator app using React.js and useState

first you need to create a new react app using npx create-react-app . if you alrwardy have a designated folder, if not then npx create-react-app react-mortgage-calculator in order to create the project folder.

The cd create-react-app and now you can start your project using npm start.

  1. Create React App using npx in the Terminal
  2. Start React App using npm start
  3. Visual Studio Code Extension for React Snippets
  4. Use Bootstrap in React App
  5. Use React icons
  6. Create React Components
  7. React Form Component
  8. Create the Form Submit Button
  9. Prevent the form from submitting
  10. React Form input group Component
  11. Use React pros for the Form input group component
  12. Use React onKeyUp event listener to calculate the loan amount
  13. Use React onInput event listener to calculate the loan amount
  14. Make a react input read only
  15. React useState hook to calculate the Loan Amount
  16. Calculate Monthly payment
  17. Convert to percentage function
  18. Convert years to months function

Add and use Bootstrap to react project

For some basic stayling I will use bootstrap, away-sly you can use anything you want. In order to use bootstrap in our react project you will need to go to:

and grab on to the CDN, but because bootstrap now updated to its Bootstrap v5.2, I will still use Bootstrap v4.6 on this project.

Now lest get the link <link rel="stylesheet" href="" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">

and copy and paste it in the public folder in you index.html file head.

Source Code:


import "./App.css";
import { FcHome } from "react-icons/fc";
import Form from "./components/Form";

function App() {
  return (
      className="App container"
      style={{ maxWidth: 500, margin: "1rem auto" }}
      <h1 className="display-1 my-5">
        <FcHome /> Mortgage Calculator{" "}
      <Form />

export default App;


Go to your source folder “src” and create a new folder called “components“. This is where all your components will be held, like the “Form.js” component and the “FormInputGroup.js” component.

Form.js Component

Now that you have your “components” folder, create the “Form.js” component by using “rfce” abbreviation, this will give you a function white the component name and export it as default at the bottom.

import React, { useState } from "react";
import { FaDollarSign } from "react-icons/fa";
import FormInputGroup from "./FormInputGroup";

function Form() {
  const [homeValue, setHomeValue] = useState("");
  const [downPayment, setDownPayment] = useState("");
  const [loanAmount, setLoanAmount] = useState("");
  const [interestRate, setInterestRate] = useState("");
  const [loanDuration, setLoanDuration] = useState("");
  const [monthlyPayment, setMonthlyPayment] = useState(0);

  function calculateLoanAmount() {
    setLoanAmount(homeValue - downPayment);
    return loanAmount;

  function calculateMonthlyPayment() {
    // Percentage conversion
    function percentageToDecimal(percent) {
      return percent / 12 / 100;

    // years to month conversion
    function yearsToMonths(year) {
      return year * 12;

      (percentageToDecimal(interestRate) * loanAmount) /
        (1 -
            1 + percentageToDecimal(interestRate),

    return monthlyPayment;

  return (
    <form onSubmit={(e) => e.preventDefault()}>
        text="Home Value "
        icon={<FaDollarSign />}
        placeholder={"Enter the value of the home"}
        onInput={(e) => setHomeValue(}
        text="Down payment"
        icon={<FaDollarSign />}
        placeholder={"Enter your funds"}
        onInput={(e) => setDownPayment(}
        text="Loan amount"
        icon={<FaDollarSign />}
        placeholder={"Enter your funds"}
        text="Interest Rate %"
        placeholder={"Enter your interest rate"}
        onInput={(e) => setInterestRate(}
        text="Loan Duration (years)"
        placeholder={"Enter the duration of your loan in years"}
        onInput={(e) => setLoanDuration(}
      <h4 className="alert alert-info fw-bold">
        Monthly payment: <FaDollarSign />

        className="btn btn-primary btn-lg w-100 center "

export default Form;

Form Input Group.js Component

import React from "react";

function FormInputGroup({
  readOnly = false,
}) {
  return (
    <div className="input-group mb-3 ">
      <span className="input-group-text ">
        {text} {icon}

export default FormInputGroup;

Video Tutorial

Check out the complete tutorial on my YouTube channel for a more indpt understanding of this React Project.

3 thoughts on “React Project Tutorial – Build Mortgage Calculator App

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.