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

useTheme returns undefined as value before using the ToggleThemeButton #9502

Closed
christiaanwesterbeek opened this issue Dec 7, 2023 · 1 comment · Fixed by #9503
Closed

Comments

@christiaanwesterbeek
Copy link
Contributor

christiaanwesterbeek commented Dec 7, 2023

What you were expecting:
Getting the theme value with the react-admin hook: useTheme().

What happened instead:
useTheme() hook returns undefined as value.

Steps to reproduce:
Go to this sandbox https://stackblitz.com/edit/github-m4as1b?file=src%2Fposts%2FPostList.tsx and see how in PostList that theme is undefined on first load of the application before using the ToggleThemeButton.

Related code:

import { useTheme } from 'react-admin;
//...
const [theme] = useTheme();
console.log('theme', theme);

Other information:

This was reported before #7805.

And fixed by @djhi on Jul 18, 2022: https://github.com/marmelab/react-admin/pull/7960/files#diff-5b4990e166ffe43cc265179d72851c8246ac299966ca41c97996202c540db43b

The fix got kind of reverted on May 3, 2023 with this commit 566fae4#diff-5b4990e166ffe43cc265179d72851c8246ac299966ca41c97996202c540db43b

Environment

  • React-admin version: 4.16.2
  • Last version that did not exhibit the issue (if applicable): see dates/versions of earlier fix and fix-revert
  • React version:
  • Browser: Chrome
  • Stack trace (in case of a JS error):
@christiaanwesterbeek christiaanwesterbeek changed the title useTheme returns undefined as value again useTheme returns undefined as value before using the ToggleThemeButton Dec 7, 2023
@adguernier adguernier self-assigned this Dec 7, 2023
@adguernier adguernier added the bug label Dec 7, 2023
@adguernier
Copy link
Contributor

Hello and thanks for this very detailed report! Reproduced.

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

Successfully merging a pull request may close this issue.

2 participants