How to detect browser in React?

To detect browser in React, we use the react-device-detect package.

To install it, we run

npm i react-device-detect

Then we use it by writing

import { isMobile } from "react-device-detect";

function App() {
  if (isMobile) {
    return <div> This content is available only on mobile</div>;
  }
  return <div> ...content </div>;
}

to use the isMobile variable to check if the content is displayed in the mobile browser.