React hooks in styled component interpolation functions #2300
Answered
by
Andarist
matt-tingen
asked this question in
Q&A
-
Is it considered safe to use react hooks in styled component interpolation functions? For example: const ExampleComponent = styled('div')(() => ({
color: useSavedColor(),
})) It seems to work without the react error one would typically see when hooks are used in an invalid manner. However, I can't find any mention of that being guaranteed by emotion and I wasn't sure if there were any gotchas to be aware of where interpolation functions are called conditionally. |
Beta Was this translation helpful? Give feedback.
Answered by
Andarist
Mar 21, 2021
Replies: 1 comment 1 reply
-
It's safe as long as you obey the rules of hooks. You need to call always the same hooks in your styled components (each render) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
matt-tingen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's safe as long as you obey the rules of hooks. You need to call always the same hooks in your styled components (each render)