Is it bad practice to use native browser Apis with React?

Asked

Viewed 17 times

0

I’ve been using React for a short time, and I use the browser’s native Apis a lot, for example to add or remove classes with events. My question is, is this a bad practice? I should try to make these changes using Hooks?

  • 3

    I would say "bad practice," yes. Most of the time, if you are using React, the browser’s native Apis become unnecessary, since React provides other means to achieve the "same result". It doesn’t make much sense to mix.

  • 2

    Difficult to answer something so broad because of corner cases. For example, it’s not nice to use document.querySelector, but you may need this to use the Reactdom.createPortal, which is then a valid use case.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.