Love Percentage Calculator App Using React Native, Expo, And Rapid API

React Native and Expo Projects For Beginners

React Native And Rapid API apps

About Love Percentage Calculator Application

A love percentage calculator is a type of application or online tool that is designed to determine the level of compatibility between two people based on their names. The idea behind these calculators is that the compatibility between two people can be determined by comparing the letters in their names and using a special algorithm to calculate a percentage. This percentage is supposed to represent the likelihood that the two people are compatible with each other.

Project setup, Package Requirements, and Code

  • Start your expo project
  • I am not going to install any third-party package for UI. But you are free to use any library package for UI parts. It depends on your app requirement.
  • Using the useState hook. Define some hooks.
const [maleName, setMaleName] = useState('')
const [femaleName, setFemaleName] = useState('')
const [loading, setLoading] = useState(false)
const [lovePercentage, setLovePercentage] = useState([])
  • The male and female field is set to empty. The love percentage array is also set to empty, initially.
  • Now to calculate the love percentage:
const calculateLove = () => {
const API_URL = `https://love-calculator.p.rapidapi.com/getPercentage?fname=${maleName}&sname=${femaleName}`
setLoading(true)
fetch(API_URL, {
method: 'GET',
headers: {
'x-rapidapi-host': 'love-calculator.p.rapidapi.com',
'x-rapidapi-key': '###############',
}
})
.then(response => response.json())
.then(data => {
setLoading(false)
console.log(data)
setLovePercentage(data)
})
.catch(err => {
console.log(err)
})
}
  • Make your account on Rapid API. Then fill in your Rapid API key. Using the above function, first, we fetch the data from Rapid API and convert those data into JSON format. Later we, replace the empty state of the love percentage with the data we fetch.
  • The rest is the UI part. It’s on you and your project requirements. You can take help from here.
  • That’s it. Now, you can test the application in the Expo Go Mobile Application.
  • If you are confused or lost, I would recommend watching a step-by-step video tutorial. Few minutes of setup and code, you will be ready to test the application.

Why do I suggest watching more videos?

I am from India and I love writing code and sharing it with the community. We all know that money is the ultimate motivation for work, and the Medium payment system uses Stripe, which has been in preview mode in India for the past 4–5 years. I waited a year on the Medium platform, but in the end, nothing worked out.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store