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

fix: setTheme now works correctly when a function is passed. #286

Merged
merged 6 commits into from
Apr 24, 2024

Conversation

trm217
Copy link
Collaborator

@trm217 trm217 commented Apr 23, 2024

Description

Fixes #277.
The dependencies of the set-state function, that is a useCallback hook it's self were faulty.
This PR defined 'theme' as a dependency of the callback-hook and removes 'forcedTheme' from the dependency.
Additionally a test-case has been added where setState is called with (theme) => theme === 'light' ? 'dark' : 'light')

This PR is based on: #285

Commits

  • test: start refactoring tests to use renderHook
  • fix: add 'theme' as a dependency to useCallback of 'setTheme' and rename parameter to value
  • test: add test for setting theme via a callback while using the previous theme value
  • docs: add text to describe accepted parameters of 'setTheme'
  • fix: remove 'forcedTheme' as a dependency from the 'setTheme' calback as it's not needed

@trm217 trm217 added the bug Something isn't working label Apr 23, 2024
@trm217 trm217 self-assigned this Apr 23, 2024
@trm217 trm217 requested a review from pacocoursey April 23, 2024 11:12
Copy link

vercel bot commented Apr 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-themes-basic ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 24, 2024 4:04pm
next-themes-tailwind ❌ Failed (Inspect) Apr 24, 2024 4:04pm
next-themes-with-app-dir ❌ Failed (Inspect) Apr 24, 2024 4:04pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Callback Version of setTheme Passes Itself
2 participants