It means you can do things like this to track media query changes.
constisMobile=useMatchMedia("(pointer: coarse) and (hover: none)");useEffect(()=>{console.log(`somehow is mobile changed it is now ${isMobile}`)},[isMobile]);
That way you will have detection logic agnostic approach and a central place to store the truth.
It may look like you are introducing a lot of unnecessary code, but it will pay off if your device detection changes dynamically during app lifecycle.
Fx. switching portrait to landscape mode may lead to serving desktop version instead of the touch one. Therefore you will need to update the store realtime with an action.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I like to have a custom hook like this in my projects. It in theory works back to IE10.
It means you can do things like this to track media query changes.
Andrew that looks ok and will also work in the last project I did.
I had to deal with different approaches for getting the touch/desktop detection right:
Things may become very annoying, that's why I decided to back my self up.
The detection logic is central for the app so you can extract it to the store. I am personally using Redux.
To supplement what has already been said in the article here is an implementation for those using some kind of store (redux in here):
Reducer + selector
And the
<Import />
component.That way you will have detection logic agnostic approach and a central place to store the truth.
It may look like you are introducing a lot of unnecessary code, but it will pay off if your device detection changes dynamically during app lifecycle.
Fx. switching portrait to landscape mode may lead to serving desktop version instead of the touch one. Therefore you will need to update the store realtime with an action.