question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't pass down styled props to an extended styled system + rebass component

See original GitHub issue

I’m creating a Position component like so:

import styled from 'styled-components'
import { position } from 'styled-system'
import { Box as Base } from 'rebass/styled-components'

const Position = styled(({ position, ...props }) => <Base {...props} />)`
  ${position}
`

export default Position

I’m expecting to be able to use it like so after importing into another file:

const Header = styled(Position)` color: red `;

<Header
  as="header"
  mb={4} // Box styled props
  pt={3} // Box styled props
  position="sticky"
  top={0}
  left={'auto'}
  right={'auto'}
  zIndex={100}
>

Do I need to be utilizing forwardRef ? Is there a way to pass down both Box props and Position props from an extended component?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jxnblkcommented, Jan 13, 2020

At first glance, this looks like it should work. Can you provide a codesandbox link with a reproduction?

1reaction
AndrewPrifercommented, Mar 5, 2020

No idea about the community in general, I mainly just prefer emotion’s css prop instead of creating one shot components for every styled div. Plus emotion seems to be react concurrent mode ready, but that shouldn’t be a concern for now I think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extending - Rebass
To extend a component, pass props through and define custom styles in the sx prop. import React from 'react'. import { Box }...
Read more >
@rebass/components - npm
@rebass/components automatically adds prop type definitions and removes style props from the underlying HTML element. See the styled-system docs ...
Read more >
Chakra UI: Sleek UI Components for React - KnowledgeHut
1. Style Props. Because Chakra UI is based on stylized systems, any component styles can be overridden or extended via props. As a...
Read more >
Limitations of Chakra UI - Ryosuke
It's similar and more feature complete to other Styled System-based UI libraries like Rebass. I've been a huge fan of utility style props...
Read more >
Understanding The Styled System - Anvil
This power extends to any imaginable CSS out there; you can pass hex values, rgba values, hsl values, etc. to our backgroundColor prop...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found