-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Functions that are interpolated in css calls will be stringified. #1085
Comments
I found out the minimum reproducible example: // @flow
import styled from '@emotion/styled';
import { css } from '@emotion/core';
const color = css`
color: ${props => props.color};
`;
const App = styled.div`
${color};
`;
export default App;
|
Just for completeness, my use case is the following:
test
edit |
Css works also in non-react scenarios, it doesnt know anything about things
like props. Just call this function with props urself and interpolate the
result instead of interpolating the function itself. Interpolated functions
are called with props only when interpolated into styled call, not css call
…On Fri, 7 Dec 2018 at 18:21, Federico Zivolo ***@***.***> wrote:
Just for completeness, my use case is the following:
import { css } from ***@***.***/core';
const styles = {
a: props => css`
color: ${props.a};
`,
b: props => css`
color: ${props.b};
`,
};
export const textStyles = (...ss) => props => ss.map(s => styles[s]);
test
it('it does not break', () => {
expect(
css`
${textStyles('a', 'b')};
`.styles
).toMatchSnapshot();
});
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1085 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AJWMkoabMhABofk7ormbnoADs-itmV8Eks5u2qOTgaJpZM4ZIhqt>
.
|
I see, but I still get the same error message (even tho, it works) if I use
|
Ok nevermind, it was something wrong with my dirty setup, it actually works inside |
@FezVrasta I'm having the same issue. What was the issue with your setup? |
This issue still ranks high on search engines, so here's a solution. // @flow
import styled from '@emotion/styled';
import { css } from '@emotion/core';
- const color = css`
+ const color = props => css`
- color: ${props => props.color};
+ color: ${props.color};
`;
const App = styled.div`
${color};
`;
export default App; |
what about conditionals such as
|
This is what I do or plan to do: https://codesandbox.io/s/determined-morse-oehqv
|
What is the solution for this issue?
How can I convert this code to remove the error? |
@alchemist-bounty try something like that; const track = ({ theme }) => css`
background-color: ${rgba(theme.colors.gray['000'], 0.25)};
`;
const StyledTrack = styled.div`
${track};
`; |
emotion
version: 10.0.2react
version: 16.3Relevant code.
What you did:
I created this function to be used in my UI library to make sure a
theme
is always definedeven if no ThemeProvider is available.
Usage:
What happened:
When I run it, in some contexts, I get this error:
and the resulting CSS, in fact, is the stringified function.
Reproduction:
https://github.com/FezVrasta/emotion-interpolation-repro
Just run the tests to see the error
Problem description:
My
withFallback
function seems to work fine if used as:but throws error if used as:
(I also tried:
with the same result)
Suggested solution:
Not sure
The text was updated successfully, but these errors were encountered: