0

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?

7
  • there is not enough informationi here , your code seems ok... when exactly do you expact to get different result? Commented Sep 30, 2020 at 8:32
  • when isMobile is true Commented Sep 30, 2020 at 8:35
  • it is dependency so it does his stuff by himself I don't have to write any code Commented Sep 30, 2020 at 8:36
  • I followed instructions but still did not work Commented Sep 30, 2020 at 8:36
  • 2
    if isMobile is true then Gela will be returned. You shouldn't ask that question here, you should go to Github and create an issue with the library. There's nothing wrong with your code, it's a matter of what happens under the hood in react-device-detect library. Commented Sep 30, 2020 at 8:37

1 Answer 1

1
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'.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.