Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

useMountedState always returns false

Đang mở
#2,598 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
react, typescript
Lĩnh vực
frontend

Hướng nghiên cứu

Start with the useMountedState entry point and run the supplied ThemeToggler example. Confirm whether the hook remains false after mounting, then collect the missing React and react-use versions and create a minimal reproduction. Done means the reported behavior and expected mounted-state result are clear enough for maintainers to investigate.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

What is the current behavior?
this always returns false, im doing something wrong ?

'use client';
import React from 'react';
import { useTheme } from 'next-themes';
import { Moon, Sun } from 'lucide-react';
import { Button } from './ui/button';
import { useMountedState } from 'react-use';

export const ThemeToggler = () => {
  const { setTheme, theme } = useTheme();
  const isMounted = useMountedState();

  const isDark = theme === 'dark';

  const Icon = isDark ? Moon : Sun;

  const toggleTheme = () => {
    setTheme(isDark ? 'light' : 'dark');
  };

  // isMounted() is always false here
  if (!isMounted()) return null;

  return (
    <Button size={'icon'} variant={'ghost'} onClick={toggleTheme}>
      <Icon size={24} />
    </Button>
  );
};

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:

What is the expected behavior?

A little about versions:

  • OS:
  • Browser (vendor and version):
  • React:
  • react-use:
  • Did this worked in the previous package version?
Ngôn ngữ chính
TypeScript
Star
44k
Fork
3.3k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của streamich/react-use

Tất cả issue của streamich/react-use

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.