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

176
Visualizações
React: Data within a map is appearing different even though the code is written the same way for both instances where used

Apologies if this is poorly written (first time posting here so feedback on how to better write posts welcome!)

I am using react map to iterate through lists of data.

                          {level1Folders.level2Folders.map(
                        (level2Folders, index) => {
                          return (
                            <li
                              id={level2Folders.folderLevel2Name}
                              key={level2Folders.folderLevel2Name + index}
                            >
                              <div
                                className="menu-item-folder-level-2"
                                onClick={() =>
                                  hideMenuItem(
                                    level2Folders.folderLevel2Name
                                  )
                                }
                              >
                                <FaIcons.FaCaretRight />
                                {level2Folders.folderLevel2Name}
                              </div>

                              <ul
                                className="manuals d-none"
                                id={level2Folders.folderLevel2Name}
                              >
                                {level2Folders.manuals.map(
                                  (manual, index) => {
                                    return (
                                      <li key={manual + index} id={manual}>
                                        <div
                                          onClick={() =>
                                            handleExplorerItemClick(manual)
                                          }
                                          className="menu-item-manual"
                                        >
                                          {manual}
                                        </div>
                                      </li>
                                    );
                                  }
                                )}

I have a method hideMenuItem(menuItemId) which will hide items based on their id's, so the idea is to set the id = to the name of the item, so when the parent item is clicked the child elements will be hidden.

  function hideMenuItem(menuItemId) {
console.log(menuItemId);
let x = document.getElementById(menuItemId);
if (x.classList.contains('d-block')) {
  x.classList.add('d-none');
  x.classList.remove('d-block');
} else {
  x.classList.add('d-block');
  x.classList.remove('d-none');

}
 }

I have 5 uses of this - level2Folders.folderLevel2Name, the only one that won't work is when trying to enter this as a parameter in hideMenuItem(menuItemId), the value here is returned as the index of the item.

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