useCss hook
See original GitHub issue@mitchellhamilton hey, I’m not sure if this is possible because I don’t know the exact internals of emotion, but from a conceptual level this might make sense.
I’m wondering if we could do something like
const MyComponent = props => {
const theme = useContext(ThemeContext);
const className = useCss({color: theme.red});
return (
<div className={className}>
MyComponent
</div>
);
}
any thoughts?
from a birds eye view, some thoughts here are, you now don’t need to worry about shouldForwardProp
you don’t need to interpolate with color: ${props => props.theme.red}
and the entire component doesn’t need to be wrapped, if the ref needs to be forwarded, then you just use forwardRef
, etc.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:6 (2 by maintainers)
Top Results From Across the Web
react-use/useCss.md at master - GitHub
useCss. React UI hook that changes CSS dynamically. Works like "virtual CSS" — it re-renders only CSS rules that change. It is different...
Read more >useCss hook - Kremling
The useCss hook allows you to write css that will only apply to your component and to its children. ... In this example,...
Read more >use-css - npm
Silly React hook for CSS Demo on CodeSandbox. install. npm install use-css. usage. import useCSS from 'use-css'. function Oopsy(props) {.
Read more >Know about the useInsertionEffect hook in React 18
The useInsertionEffect hook in React 18 is mostly for CSS-in-JS libraries for inserting global DOM nodes like 'style' or SVG 'defs' in the ......
Read more >useCss | API Reference - Nightwatch.js
useCss (). Sets the locate strategy for selectors to css selector , therefore every following selector needs to be specified as css. Parameters ......
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
We’ll rethink how this problem can be handled right now. We are working on a v11, so we’d like to address problems like this. The solution is not obvious - so no promises yet, but please know that we are going to think about this.
Following the migration from emotion@9 to emotion@10 with
react-toastify
, I am also facing an issue here. I have the following hook:Far away from any
render
, So I cannot use theClassNames
render prop tip. A hook would be really nice.Do you see how I could make it work without using deprecated library?