Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

useWindowSize does not work on App Router (nextjs)

Aperta
#2,532 2 commenti 6 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
nextjs, react, typescript
Ambito
frontend, web-dev

Direzione di ricerca

Start by reproducing the reported hydration warning with Next.js 14 App Router and the useWindowSize entry point shown in the issue. Compare the server and browser results, then verify that the hook returns the browser's window dimensions without a width mismatch.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
TypeScript
Stelle
44k
Fork
3.3k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di streamich/react-use

Tutte le issue di streamich/react-use

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.