user1547174 user1547174 - 2 months ago 11
Javascript Question

Return value prop of component in reactjs

Right now I have a component:

<Icon name='close' value={ tag } onClick={ this.deleteTag.bind(this) } />


And an
onClick
event:

deleteTag = (event) => {

const tag = event.currentTarget.value; //returns undefined

}


Is there a way I can return the
value
prop of my
Icon
component? My attempt as shown above would not work...

Thanks in advance!

Answer

The Icon itself, does not have a value.. It's not an input

What you could do, is the following:

<Icon name='close' value={ tag } onClick={ () => this.deleteTag(tag) } />

Now the tag should be available in your deleteTag method.