Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It doesn't work reactively in react version 18 or higher. #293

Closed
ynifamily3 opened this issue Apr 27, 2022 · 2 comments · Fixed by #294
Closed

It doesn't work reactively in react version 18 or higher. #293

ynifamily3 opened this issue Apr 27, 2022 · 2 comments · Fixed by #294

Comments

@ynifamily3
Copy link
Contributor

When I build the react app above v18,

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import './index.css';

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
);

It doesn't reactive on resize.

export const useScreenSize = () => {
  const mobile = useMediaQuery({
    maxDeviceWidth: 767,
  });
  const tablet = useMediaQuery({
    minDeviceWidth: 768,
    maxDeviceWidth: 1439,
  });
  const pc = useMediaQuery({
    minDeviceWidth: 1440,
  });
  return useMemo(() => ({mobile, tablet, pc}), [mobile, tablet, pc]);
};

@ynifamily3 ynifamily3 changed the title Doesn't reactive in React v18 It doesn't work reactively in react version 18 or higher. Apr 27, 2022
@WhiteYaksha
Copy link

WhiteYaksha commented Apr 28, 2022

Same here, the state doesn't change when resizing

EDIT: For anyone having issues because of React 18, you can try to use ahooks which has a built in hook for responsive

https://ahooks.js.org/hooks/use-responsive/

@yocontra
Copy link
Owner

yocontra commented May 9, 2022

Fixed and published as beta7! Will probably release 9.0.0 as stable if everyone reports that it works fine for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants