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

146
Views
How do I remove the undefined?

If the user does not have a first, middle, or last name, it will show an undefined. How can I remove the underline but instead I will put a saying that it they need to click this link to update their profile enter image description here

import { useSelector } from "react-redux";

const mapState = ({ user }) => ({
  currentUser: user.currentUser,
});

const Settings = () => {
  const { currentUser } = useSelector(mapState);

  const name =
    currentUser?.firstName +
    " " +
    currentUser?.middleName +
    " " +
    currentUser?.lastName;

  return (
    <>
       <Typography>Hello, {name}</Typography>
    </>
  );
};

export default Settings;
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

import { useSelector } from "react-redux";

const mapState = ({ user }) => ({
  currentUser: user.currentUser,
});

const Settings = () => {
  const { currentUser } = useSelector(mapState);

  const nameComponents = [
    currentUser?.firstName, 
    currentUser?.middleName,
    currentUser?.lastName
  ].filter(part => Boolean(part));
  const name = nameComponents.join(" ")

  return (
    <>
       <Typography>Hello, {name}</Typography>
       { nameComponents.length !== 3 && <button @click="...">
         Fill lackink parts of your name
       </button>}
    </>
  );
};

export default Settings;
about 4 years ago · Juan Pablo Isaza Report

0

You can do a simple checking while rendering Typography component as below

  return (
    <>
       {(
          currentUser?.firstName && 
          currentUser?.middleName && 
          currentUser?.lastName
        ) 
        ? <Typography>Hello, {name}</Typography> 
        : <div>whatever </div>
    </>
  );
about 4 years ago · Juan Pablo Isaza Report

0

Map and/filter the values

Assuming currentUser ONLY has firstName, lastName and middleName

We need more testing if there are roles or addresse etc

const currentUser = { "firstName" : "John", "lastName": "Doe" }

const names = Object.values(currentUser).map(name => name || "");
console.log(names.join(" "))
console.log("Fullname?",names.filter(name => name).length >= 2)

// destructing is not useful here
// const { firstName, middleName, lastName} = currentUser
// console.log(firstName, middleName, lastName)

about 4 years ago · Juan Pablo Isaza Report
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!