0

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

2 Answers 2

1

try below:

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Jed, i am a bit rusty, I was just going to upate thhe post as solved.
1

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>

1 Comment

wow, that is great, i did not come accorss this idea before. thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.