Nika Roffy
Nika Roffy

Reputation: 941

Reactjs Javascript if/else not working correctly

I have this if/else statement

import { isMobile } from 'react-device-detect'

const MoneyManagementOffers = ({ text, title }) => {
  const renderContent = () => {
  const checkDevice = isMobile ? <h1>Gela</h1> : <h1>Margo</h1>

  return checkDevice
}

Somehow it will always return <h1>Gela</h1> and I don't know why, Any suggestions, please?

Upvotes: 0

Views: 64

Answers (1)

groul
groul

Reputation: 119

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

const App = () => {
  const checkDevice = isMobile ? <h1>Gela</h1> : <h1>Margo</h1>;
  return <>{checkDevice}</>;
};

export default App;

This code works fine, maybe you need to switch to/from a mobile device view in your dev tools to see 'Gela' or 'Margo'.

Upvotes: 1

Related Questions