Accepted answer

you should use your to achieve what you want. with this, you'll know which dropdown you're hovering and apply any logic you need. you can check for example if the dropdown you're hovering is the category dropdown like this:

if( === "class name of your element")

then you use it this state in your code to show/hide the element you want.

you can check an example on this fiddle i've created:

i don't think you're going to need the onmouseleave event, but if you need you can follow the logic i've applied to onmouseover

hope it helps.


1. you need to save the state of each <li> item in an array/object to keep a track of hover states.

  constructor(props) {
    this.state = {
      hoverstates: {} // or an array

2. and set the state of each item in the event handlers.

handlemouseover = e => {
      hoverstates: {
        []: true
  handlemouseleave = e => {
      hoverstates: {
        []: false

3. you need to set the id (name doesn't work for <li>) in a list of menu items.

also make sure to add key so that react doesn't give you a warning.

  render() {
    const { hoverstates } = this.state;
    const menuitems = [0, 1, 2, 3].map(id => (
        classname={hoverstates[id] ? "hovering" : ""}
        {hoverstates[id] ? (
          <ul classname="dropdown menu">
            <li>#{id} computerss & office</li>
            <li>#{id} electronics</li>
        ) : null}

    return <ul classname="menu">{menuitems}</ul>;

4. the result would look like this.

demo result

you can see the working demo here.

edit p7xr8ro9jx

shameless plug

i've written about how to keep a track of each item in my blog, keeping track of on/off states of react components, which explains more in detail.

Related Query

More Query from same tag