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

175
Views
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
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!