Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda