-1

i want to display a button only on mobile and desktop devices. if user is using application on tablet device i dont want to display the button using react and typescript.

below is my code,

function Parent() {
    return(
        <button>hide me </button>
    );
}

I am new to programming. could someone help me with this. thanks.

Samathingamajig
  • 1,447
  • 1
  • 5
  • 20

3 Answers3

-1

Typically this is done using CSS media queries, I recommend going that route. If that isn't useful you can also checkout this answer on a similar question Detect if device is tablet.

BeFoRE
  • 38
  • 4
-1

There are already libraries to do that for you, you could check this one:

https://www.npmjs.com/package/react-device-detect

Joshue
  • 27
  • 1
  • 6
-2

I don't think it is quite possible to do this especially as a beginner.

I'm barely an amateur in coding and I know you can check for the screen width or whether it is a device with a touchscreen, but recognizing if the user is using a tablet is not possible to do it with some simple codes.

MrJami
  • 176
  • 11