Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
How to Initialize Materialize Dropdown Button in React?

I have this code, and am trying to get the dropdown button to work. I can get the button to appear but nothing happens when clicked.

import React, {useContext} from 'react';
import {Link, useNavigate} from 'react-router-dom';
import {UserContext} from '../App'
import M from 'materialize-css'

const NavBar = ()=>{
    const navigate = useNavigate()
    const {state, dispatch} = useContext(UserContext)
    const renderList = () =>{
        if(state){
            return [
                <div>
                    <a class='dropdown-trigger btn' href='#' data-target='dropdown1'>Drop Me!</a>

                    <ul id='dropdown1' class='dropdown-content'>
                        <li><a href="#!">one</a></li>
                        <li><a href="#!">two</a></li>
                        <li class="divider" tabindex="-1"></li>
                        <li><a href="#!">three</a></li>
                        <li><a href="#!"><i class="material-icons">view_module</i>four</a></li>
                        <li><a href="#!"><i class="material-icons">cloud</i>five</a></li>
                    </ul>
                </div>
                
            ]
        }
        else{
            return [
            <li><Link to="/login">Login</Link></li>,
            <li><Link to="/signup">Sign Up</Link></li>
            
            ]
        }
    }

    return(
        <nav>
        <div className="nav-wrapper green" >
            <Link to= {state?"/":"/login"} className="brand-logo left">FungEye</Link>
            <ul id="nav-mobile" className="right">
                {renderList()}
            </ul>
        </div>
        </nav>
    )
}

export default NavBar;

I would like the dropdown button to dropdown with the list as expected.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Please, try something like this

 <div id="dropdown1">
  <a class="dropdown-trigger btn" data-toggle="dropdown1" href="#">
    Drop Me!
  </a>
  <ul class="dropdown-content">
    <li>
      <a href="#">one</a>
    </li>
    <li>
      <a href="#">two</a>
    </li>
    <li class="divider" tabindex="-1"></li>
    <li>
      <a href="#">three</a>
    </li>
    <li>
      <a href="#">
        <i class="material-icons">view_module</i>four
      </a>
    </li>
    <li>
      <a href="#">
        <i class="material-icons">cloud</i>five
      </a>
    </li>
  </ul>
</div>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!