Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Unable to style Link components with styletron #171

Closed
ghost opened this issue Aug 12, 2018 · 2 comments
Closed

Unable to style Link components with styletron #171

ghost opened this issue Aug 12, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 12, 2018

I'm having trouble styling Link components. If you nest an anchor element or anchor component, Fusion will create another anchor instead of rendering one anchor. If you pass the Link component into styletron's withStyle, Fusion crashes.

Is there a way to style Links with styletron? I'd prefer to avoid using inline style and nesting a random element for the purposes of styling.

@rtsao
Copy link
Member

rtsao commented Aug 12, 2018

You can do this two ways:

import {styled} from "styletron-react";
const StyledLink = styled(Link, /* ... */);

<StyledLink>Hello world</StyledLink>

or:

import {styled} from "styletron-react";
const StyledAnchor = styled("a", /* ... */);

<StyledAnchor $as={Link}>Hello world</StyledAnchor>

The styled function creates a styled element component from a tag name or arbitrary component React component.

Compositional functions (such as withStyle, withTransform, etc.) create new styled element components by composing new styling logic with existing styled element components.

@ghost
Copy link
Author

ghost commented Aug 13, 2018

Solid! This worked great! Thanks @rtsao!

@ghost ghost closed this as completed Aug 13, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant