Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass props to rebass Button component with typescript is not working #1008

Open
yokiijay opened this issue Jul 6, 2020 · 3 comments
Open

Comments

@yokiijay
Copy link

yokiijay commented Jul 6, 2020

Here is the higher component I built based on rebass Button

Can't pass props to Button if I give ButtonProps to Btn, is there any way to do that?

import { FC } from 'react'
import { Button, ButtonProps } from 'rebass'

const Btn: FC<ButtonProps> = ({...props}) => {
  return(
    <Button {...props}></Button>
  )
}

export default Btn

image

@yokiijay
Copy link
Author

yokiijay commented Jul 6, 2020

Right now, I can only import separate props from styled-system one by one to make it work.

import { FC } from 'react'
import { Button, ButtonProps } from 'rebass'
import { ColorProps, SpaceProps, LayoutProps } from 'styled-system'

const Btn: FC<ColorProps & SpaceProps & LayoutProps> = ({...props}) => {

  return(
    <Button {...props}></Button>
  )
}

export default Btn

@Howard86
Copy link

Howard86 commented Oct 15, 2020

I think you are missing the children from FC

The following works well for myself.

import React, { FC } from 'react';
import { Button as RebassButton, ButtonProps } from 'rebass';

const Button: FC<ButtonProps> = (props) => {
  const { children, ...rest } = props;
  return <RebassButton {...rest}>{children}</RebassButton>;
};

export default Button;

(Edit: I have removed React.memo part as it's irrelevant to the question)

@mneghin
Copy link

mneghin commented Feb 28, 2022

Recently I faced the same problem as well. A solution would be to destructure css property { children, css, ...props }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants