Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove function In ReactJs in mobile view

Suppose I have a component that has two functions which are run when the app is started so when I switch app in responsive width and that width is mobile so i want to run only one function in that the second one has to be removed

does anyone can help??

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just get window width and set if statement.

const width = window.innerWidth

if (width === 400) {
  runFunction()
}

or

const width = window.innerWidth

const runFunction = () => {
  if (width === 400) {
    // ...function logic
    return
  }
   
  return
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading