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

124
Visualizações
export functional component with injectIntl without using default export

Now I have two components, List and Item. Since Item is only used in List, I want to put them in a single JSX file. However, the item has to be wrapped with injectIntl to enable the functionality of the i18n string.

I found that I cannot export Item without adding default, while List is exported by default already and the only way I can do is to import Item from another file or pass the translated string from List to Item.

I wonder why can't I do with the following code and is there any better practice I can follow while using injectIntl in functional components?

// for simplicity imports are omitted
// Item and List are written in the same file (List.jsx)

const Item = ({content, intl}) => {
  return (
    <>
      <h1>{intl.formatMessage(content.i18nkey)}</h1>
      <img src={content.imgURL} />
    </>
  )
}

export injectIntl(Item); // this line is reported syntax error

const List = ({contents}) => {
  return (
    contents.map((content) => 
      <Item content={content}/>
    )
  )
}

export default List;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This works fine:

export const Item = injectIntl(
 (props) => {...} 
)

Just don't forget the the brackets, i.e. const Item = injectIntl(arrow function)

Also use rest to get all existing parameters. And remove spaces from your id, otherwise querySelector will not work. In below case id is also used as a displayed label in the cell:

export const TableCellId = injectIntl((props) => {
  const { id, intl, ...rest } = props
  return (
    <TableCell id={removeSpaces(id)} {...rest}>
      {mytanslation(intl, id)}
    </TableCell>
  )
})
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