0

i have an issue, i need when i click on listItem, console.log it's "category" value but it return "undefined".

function Portfolio() {

    const handleClick  = (e)=>{
        console.log(e.target.category)

    }
    return (
        <Section>
            <Title><TitleSpan>My</TitleSpan> Portfolio</Title>
            <List>
                <ListItem active category={"all"} onClick={handleClick}>All</ListItem>
                <ListItem category={"html" }onClick={handleClick}>HTML</ListItem>
                <ListItem category={"photoshop"} onClick= 
                  {handleClick}>Photoshop</ListItem>
                <ListItem category={"wordpress"} onClick= 
                    {handleClick}>Wordpress</ListItem>
                <ListItem category={"mobile"} onClick={handleClick}>Mobile</ListItem>
            </List>
        </Section>
    )
}

3 Answers 3

2

If you don't need the event param, you can just pass the category this way too.

onClick={() => handleClick('mobile')}

const handleClick  = (category)=>{
  console.log(category)
}
Sign up to request clarification or add additional context in comments.

Comments

1

Because we don't have property category. You can use name instead.

const handleClick = (e) =>{
    console.log(e.target.name)
}

<ListItem active name="all" onClick={handleClick}>All</ListItem>

1 Comment

i tried to change category to name but still the issue founded
0

You can pass 2nd argument.

<ListItem active category={"all"} onClick={(e)=>handleClick(e, 'all')}>All</ListItem>

After than you can collect value like this.

const handleClick  = (e, category)=>{
        console.log(category)

    }

Comments

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.