Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
Where to put javascript code with styled components?

Can't figure out where to place this code for my sorting of employees in my styled component. Usually I would just place code above the return statement of a functional component. But React isn't having it.

import styled from "styled-components";
import EmployeeAvatar from "../EmployeeAvatar";

const Styles = styled.div`
  .employee-finder-content {
    width: 1440px;
    background-color: rgb(240, 240, 240);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
  }
`;

export const Content = ({
  employees,
  filtered,
  grabEmployeeData,
  updateDisplayProfile,
}) => (

    employees.sort((a, b) => {
        if (a.name > b.name) {
        return 1;
        } else {
        return -1;
        }   
    })


  <Styles>
    <div onClick={updateDisplayProfile} className={"employee-finder-content"}>
      {filtered === null
        ? employees.map((person) => {
            return (
              <EmployeeAvatar
                name={person.name}
                title={person.title}
                // displayEmployeesProfile={displayEmployeesProfile}
                grabEmployeeData={grabEmployeeData}
                id={person.id}
                key={person.id}
              />
            );
          })
        : filtered.map((person) => {
            return (
              <EmployeeAvatar
                name={person.name}
                title={person.title}
                // displayEmployeesProfile={displayEmployeesProfile}
                grabEmployeeData={grabEmployeeData}
                id={person.id}
                key={person.id}
              />
            );
          })}
    </div>
  </Styles>
);

I tried wrapping the employees.sort in curly braces {} and it still doesn't work. Any thoughts?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're trying to put multiple statements (with an implicit return) inside the Content function without wrapping that function in curly braces. Wrap it in curly braces and add a return statement:

export const Content = ({
  employees,
  filtered,
  grabEmployeeData,
  updateDisplayProfile,
}) => { // <--- here
  
  employees.sort... // etc.

  return (
    <Styles>
      //...
    </Styles>
  );

}; // <--- and here
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda