Skip to content

Instantly share code, notes, and snippets.

@JamesBliss
Last active May 27, 2020 11:27
Show Gist options
  • Save JamesBliss/39ee33ddbf291ee3315eb7854777d704 to your computer and use it in GitHub Desktop.
Save JamesBliss/39ee33ddbf291ee3315eb7854777d704 to your computer and use it in GitHub Desktop.
How to access things in styled components

Styled components -> how to access other styled component or yourself!

& + &

& + ${() => Foo}

usage:

const Button = styled('button')`
  & + ${() => Button} {
    margin-left: 10px;
  }
`;

If you are using a newer version of styled components I believe & + & should work now though.

Component + &

${Foo} + &

usage:

const Box = styled('div')``;

const Button = styled('button')`
  ${Box} + & {
    margin-top: 10px;
  }
`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment