Reputation: 116
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
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