yocontra/react-responsive

onChange is not fired

tambaqui opened this issue ยท 3 comments

onChange event is not fired. Tested with react 17.0.1

Can you give more specifics - code sample, what browser you're testing in, etc.

Tested with a small component similar to the one in the doc:

import { useMediaQuery } from 'react-responsive'

const Sample = () => {

  const handleMediaQueryChange = (matches) => {
    console.log('matches', matches)
  }
  
  const isWide = useMediaQuery(
    { minDeviceWidth: 1280 }, undefined,  handleMediaQueryChange
  );

  return (
    <div>
        Screen is wide: {isWide ? '๐Ÿ˜ƒ' : '๐Ÿ˜ข'}
    </div>
  )
}

export default Sample

I'm seeing that not only the onChange fails. IsWide detection also fails, which always returns ๐Ÿ˜ƒ

Tested in Windows 10, with react 17.0.1, react-scripts 4.0.0, react-responsive 8.1.0
Browsers: Chrome 86.0.4240.183, Firefox 82.0.2. Same results in both.

I have found the problem. Sorry, my mistake, I was using minDeviceWidth in testing with desktop browsers, when I should be using minWidth.