Comments (4)
Since I have hit this problem a couple of times now because it's a been a while between projects... and this page seems the top hit in google when I search for it...
Component doesn't work, you need to use "is" ( I think there is another issue explaining this, but can't find it at the moment )
<NavItem
to='/'
is={Link}
children='Home' />
from rebass.
Because googling and still get top for this issue, use as
instead of is
import { Link as RouterLink } from 'react-router'
import { Link as RebassLink } from 'rebass'
export default props =>
<RebassLink
{...props}
as={RouterLink}
/>
#468
#539
https://www.styled-components.com/docs/api#as-polymorphic-prop
from rebass.
No worries. I haven't documented that very well yet. The basic way is something like this:
import { NavItem } from 'rebass'
import { Link } from 'react-router'
const MyComponent = () => (
<div>
<NavItem
to='/'
Component={Link}
children='Home' />
</div>
)
I haven't written any tests for this specific case, but this should work.
If you'd like to use the NavItem styles throughout your app, I'd recommend creating a wrapper component for this:
import { NavItem } from 'rebass'
import { Link } from 'react-router'
const MyNavItem = (props) => (
<NavItem
{...props}
Component={Link} />
)
export default MyNavItem
Then you'd use it like this:
<MyNavItem to='/' children='Home' />
from rebass.
Some point from me. Don't be too clever ;)
Below code WILL NOT work.
import { Button } from 'rebass'
const LinkButton = styled(Button).attrs({
is: Link,
})`
text-decoration: none;
`
React complains about calling component directly and styled-components crashes.
Solution to this is similar to above:
import { Button } from 'rebass'
const StyledButton = styled(Button)`
text-decoration: none;
`
function LinkButton(props) {
return <StyledButton {...props} is={Link} />
}
from rebass.
Related Issues (20)
- Is there a way for variants to inherit properties from default style? HOT 1
- Theme spacing doesn't work on the new version of emotion-theming HOT 9
- Checkbox component is broken with styled-components v5x.x HOT 3
- Is it possible to use color variables with gradients when specifying the theme HOT 1
- How can I change 'Text'(div) component to other semantic element? HOT 2
- Emotion 11 Support HOT 1
- [Question] What is the release cadence? HOT 1
- Custom breakpoints not working HOT 1
- Heading components not getting styles from theme (Emotion 11)
- Update for react 17+ HOT 7
- Is this project still maintained? HOT 10
- Typescript error when using sx prop in a Box component HOT 2
- @emotion/react ThemeProvider not working HOT 2
- Is there a way to use keyframes with Rebass? HOT 1
- Predefined styles for components conflict with custom styling HOT 1
- checkbox issue
- Style issues when clicked HOT 1
- Checkbox in label is technically invalid HOT 1
- Can I change theme CSS based on parent class?
- In-docs Voice/Text Chat 🤩
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rebass.