1

I have scirpt for mobile multilevel menu. How can I get it work in react? I have something like this:

export function mobileNavigation() {
  let navElements = document.querySelectorAll('.nav');
  let backButton = document.querySelector('.back-nav');

  navElements.forEach(el => {
    el.addEventListener('click', itemClicked)
  })
  //more code
}

Then in my mobilenav component i have:

componentDidMount() {
  mobileNavigation();
}

But it doesnt work.. I mean I know why but I don't know how to solve it. How can I get my script available the whole time not only once when component mounts?

1
  • are you imported it? Commented Feb 2, 2018 at 13:42

1 Answer 1

1
import {mobileNavigation} from '../../some address'

mobileNavigation()
Sign up to request clarification or add additional context in comments.

1 Comment

please Approve as right answer if it helps stackoverflow.com/help/someone-answers

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.