Skip to content

Instantly share code, notes, and snippets.

@paulodutra
Last active August 17, 2023 18:52
Show Gist options
  • Save paulodutra/c25ff2f841ff8f69584fbc0596d32e2e to your computer and use it in GitHub Desktop.
Save paulodutra/c25ff2f841ff8f69584fbc0596d32e2e to your computer and use it in GitHub Desktop.
Three examples of buttons components using type for props without React.PropsWithChildren
import React, { ReactNode } from 'react'
type ButtonProps = {
lenghtButton?: string;
children: ReactNode;
onClick?: () => void
};
export const Button = (props: ButtonProps) => {
return (
<button onClick={props.onClick} style={{fontSize: props.lenghtButton}}>
{props.children}
</button>
)
}
import React from 'react'
type ButtonProps = React.PropsWithChildren<{
lenghtButton?: string;
onClick?: () => void
}>
export const Button = ({children, lenghtButton, onClick}: ButtonProps) => {
return (
<button onClick={onClick} style={{fontSize: lenghtButton}}>
{children}
</button>
)
}
import React from 'react'
type ButtonProps = React.ComponentProps<"button"> & {
lenghtButton?: string
}
export const Button = ({children, lenghtButton, ...props}: ButtonProps) => {
return (
<button
style={{fontSize: lenghtButton}}
{...props}
>
{children}
</button>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment