useColorMode not reactive when using multiple instances
See original GitHub issueWhen I use useColorMode()
in different places, different refs are returned, which means reactivity between them doesn’t work, e.g.
// ColorMode toggle component
<template>
Some color mode toggle
</tempalte>
<script setup lang="ts">
const color = useColorMode()
// manipulate color with toggle...
</script>
// Some other component
<template>
<div :style="{ 'background-color': bgColor }">
Some HTML
</div>
</tempalte>
<script setup lang="ts">
const color = useColorMode()
const bgColor = computed(() => color === 'light' ? '#fff' : '#000')
</script>
Now, when I use the toggle to change the color, the second component will not react…
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
Bug: useColorMode returned undefined colorMode if you use ...
Bug report Describe the bug I'm not sure, this is a bug or just the default behaviour of react hooks, but let me...
Read more >useColorMode not working for Chakra UI Footer Component
Alternative problem: Maybe you have multiple ChakraProvider 's - One that wraps your whole App, and one that wraps everything except your footer ......
Read more >Functions | VueUse
useColorMode -reactive color mode (dark / light / customs) with auto data ... onStartTyping-fires when users start typing on non-editable elements.
Read more >Color Mode - Chakra UI
Color Mode. Chakra UI comes with built-in support for managing color mode in your apps. By default, most of Chakra's components are dark...
Read more >12 React Hooks Every React Developer Should Know
React hooks are highly reusable parts of functionality. Hooks let us Eencapsulate side effects and compose and reuse logic. For most use cases, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I update the demo with createGlobalState
I think if you want reactive
colorMode
in multiple instance it would be a little better to export its module (less function call) or try createGlobalState.