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

useWindowSize does not work on App Router (nextjs) #2532

Open
ghostlexly opened this issue Dec 18, 2023 · 1 comment
Open

useWindowSize does not work on App Router (nextjs) #2532

ghostlexly opened this issue Dec 18, 2023 · 1 comment

Comments

@ghostlexly
Copy link

ghostlexly commented Dec 18, 2023

What is the current behavior?

Gives an error:
app-index.js:32 Warning: Prop width did not match. Server: "Infinity" Client: "1290"

This is probably due to app router running the code on server side even with "use client" specified.

Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below:

  • install nextjs 14
  • use app router
  • create a component
"use client";

import useWindowSize from "react-use/lib/useWindowSize";

const StepSubmittedWidget = () => {
  const { width, height } = useWindowSize();

return (<></>)
}

export default StepSubmittedWidget;

What is the expected behavior?

Gives the browser's window sizes

A little about versions:

  • OS: MacOS
  • Browser (vendor and version): Chrome
  • React: 18.2.0
  • react-use: 17.4.2
  • Did this worked in the previous package version? No
@vincentjr
Copy link

Running into the same issue here :x

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

No branches or pull requests

2 participants