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

149
Views
hide only the div clicked in react instead of all elements returning in map function

the json response is received form dummy user data API. when I click on read more button all components returning in map get expanded/hidden . I want it to show/hide the text of specific div that is clicked

    import React, { useState } from 'react'
    const UserBlock = (props) => {
      //styles strings
      const infoTitle = `font-bold`
      //Hooks
      const [laodMoreClicked, loadMoreStatus] = useState(false)
      const [viewMoreClass, setViewMoreClass] = useState("hidden")
//functions
      const viewMore = () => {
        laodMoreClicked === true ? loadMoreStatus(false) : loadMoreStatus(true);
        laodMoreClicked === true ? setViewMoreClass("hidden") : setViewMoreClass("")
      }
const singleUser = props.userArray.map((user, index) => {
        return (
          <div key={index} className="
        bg-gray-900 text-white m-2 p-10 w-full rounded-2xl shadow-lg
     m-8 md:w-1/4 lg:w-1/6">
            <p className={`${infoTitle} text-xl`}>  username:  {user.name}</p>
            <div className={viewMoreClass}>
              <p className={infoTitle}>  email:  {user.email}  </p>
              <p className={infoTitle}>  website:  {user.website}  </p>
              <p className={infoTitle}>  phone: {user.phone}  </p>
              <p className={infoTitle}>  address: </p>
              <p className={infoTitle}>  suite: {user.address.suite}  </p>
              <p className={infoTitle}>  street:  {user.address.street}  </p>
              <p className={infoTitle}>  city:  {user.address.city}  </p>
              <p className={infoTitle}>  zipcode: {user.address.zipcode}  </p>
            </div>
            <div>
              <button onClick={viewMore}>
                View {laodMoreClicked === true ? `${index} Less` : "More"}
              </button>
            </div>
          </div>
        )
      })
      return (
        <div className='flex flex-wrap w-full justify-center '>
          {singleUser}
        </div>
      )
    }
    export default UserBlock
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!