'How to render element based on data from FaunaDB in Next.js
I'm trying to render different elements based on the users' job profile status. I'm using FaunaDB with useSWR to fetch the data, and I'm getting the following object back when doing a console.log(userData):
jobProfile: {status: 'active'}
I'm importing and calling a function named profileStatusIndicator(userData) on a page with the userData as a parameter.
export const profileStatusIndicator = (userData) => {
console.log(userData) //returns object: jobProfile: {status: 'active'}
const profileStatus = (status) =>
userData?.jobProfile?.status?.includes(status)
console.log(profileStatus) //returns nothing
if (profileStatus("active")) return active
if (profileStatus("occupied")) return occupied
if (profileStatus("inactive")) return inactive
const active = (
<>
<span className="absolute top-1 right-1 block h-6 w-6 rounded-full bg-green-400 ring-2 ring-white" />
</>
)
const occupied = (
<>
<span className="absolute top-1 right-1 block h-6 w-6 rounded-full bg-yellow-400 ring-2 ring-white" />
</>
)
const inactive = (
<>
<span className="absolute top-1 right-1 block h-6 w-6 rounded-full bg-gray-400 ring-2 ring-white" />
</>
)
}
Doing a console.log(userData) returns the object. If I do a console.log(profileStatus) it does not return anything in the console.
Can you spot what I'm doing wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
