Joaquin86
Joaquin86

Reputation: 116

trying to go through array in react

Hope you can clarify this issue I am having: I have this array:

const LAN = [
    {disp: 'EN'
    
    },
    {disp: 'ES'
    
    },
    {disp: 'CZ'
    
    },
];

I am trying to list it on a ul as li, I need to access the value of each li elemnt with the onClick function:

  return (
        <section className="language">
          <div className="language__display">
                <span id="current"><FiChevronDown size={24}/></span>
                <p>EN<span id="current"></span>
                <ul>
                    {
                        LAN.map((L,index)=>{
                        <li onClick={handleClick} key={index}>{L.disp}</li>//line 33
                        })
                    }
   
                </ul>
                </p>
          </div>
        </section>
    )
}
      

for some reason that I dont manage to understand I am getting error when the page loads:

./src/Providers/Languaje.jsx
  Line 33:25:  Expected an assignment or function call and instead saw an expression  no-unused-expressions

Search for the keywords to learn more about each error.

Does anyone knows the issue here? thanks

Upvotes: 0

Views: 48

Answers (2)

ttannerma
ttannerma

Reputation: 11

Try below. I added a return statement, and you said you wanted access to each li value in the click handler so I added the element as parameter on the click handler.

<ul>
    { LAN.map((L,index)=> {
         return <li onClick={(e) => handleClick(e, L) } key={index}> {L.disp} </li>
      })
    }
</ul>

Upvotes: 1

Jed Monsanto
Jed Monsanto

Reputation: 31

try below:

LAN.map((L,index)=>{ return ({L.disp})//line 33 })

Upvotes: 1

Related Questions