DEV Community

Sheo Sagar
Sheo Sagar

Posted on

How To Create Dynamic Dropdown In React?

Dynamic dropdown you can create with help of the map() method of the javascript. Need to create a separate component It helps to create for the repeated anchor then go to header file or where you need this the component then you can call as below code:

Navlist.js
import React from 'react'
import {Link} from 'react-router-dom'

export default (props) => {
const renderSubMenu = () => props.subMenu.map((item, i) =>

  • {item.name}
  • );
    return(
    <>
  • {props.navName} {props.subMenu ? (typeof props.subMenu=="object" ?
      {renderSubMenu()}
    : null) : null}

  • </>
    )
    }

    Explore in details
    https://www.anythinglearn.com/2019/11/how-to-create-dynamic-dropdown-in-react.html

    Top comments (1)

    Collapse
     
    dance2die profile image
    Sung M. Kim

    Hi Sheo.

    DEV generally asks that folks share their posts in full if possible and there is tooling provided (dev.to/settings/publishing-from-rss) to make it so that it's relatively easy to repost from outside blogs.

    And for SEO purpose, you can add canonical_url in the frontmatter.

    Hope you'll consider sharing the full post going forward.