Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Dynamically load and select custom item objects in React

I am dynamically creating a list from an API call on my backend.

data && data.map( business => BusCard(business) ) where data contains a giant list of businesses from an API call.

On my gui I want to be able to select an item to process it later in some other functions (change border color of selected item, get businesses reviews, ratings, etc...). I was only able to get the selection working, but I think the way I am doing it here is very hacky.

I need some pointers on how I should go about doing this.

Namely

  function setBusiness() 
  {
    currentBusiness = item;
  }

and the custom onClick I just call that. To set it. <Box ... onClick={setBusiness}>

I call this function whenever i need to get the item that was selected.

export function getCurrentSelectedBusiness()
{
  return currentBusiness;
}

enter image description here

My custom "BusCard" That shows the information from a business.

import { AspectRatio, Box, Image} from "@chakra-ui/react";
import React, {useState} from 'react';

let currentBusiness = "";

export function getCurrentSelectedBusiness()
{
  return currentBusiness;
}

function BusCard(item) 
{
  function setBusiness() 
  {
    currentBusiness = item;
  }

  return(
    <Box p="4" maxW="sm" borderWidth="1px" borderRadius="lg" overflow="hidden" mt={6}  onClick={setBusiness}>
      <AspectRatio maxH="100px">
        <Image src={item.image_url} alt={item.alias} size="sm" />
      </AspectRatio>
      <Box p="2">
        <Box
          mt="1"
          fontWeight="semibold"
          as="h4"
          lineHeight="tight"
          alignItems
        >
          {item.name} 
          <br />
          {item.review_count} Reviews
        </Box>
        <Box display="flex" alignItems="baseline">
          <Box
            color="gray.500"
            fontWeight="semibold"
            letterSpacing="wide"
            fontSize="xs"
            textTransform="uppercase"
            ml="5"
          >
            {item.location.display_address}
            <br />
            {item.phone}
          </Box>
        </Box>
      </Box>
    </Box>
  )
}


export default BusCard;
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!