Giter Club home page Giter Club logo

Comments (4)

keithn avatar keithn commented on August 26, 2024 9

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.

detikpw avatar detikpw commented on August 26, 2024 1

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.

jxnblk avatar jxnblk commented on August 26, 2024

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.

R0bson avatar R0bson commented on August 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.