I am using [email protected] and I am trying to create a custom Button component using react-bootstraps Button, adding another prop, isLoading.
Because of the way react-bootstrap types are defined I ended up importing some helpers types and copying a part of react-bootstrap types:
import React from 'react'
import { Button as Btn, ButtonProps } from 'react-bootstrap'
import { BsPrefixProps, ReplaceProps } from 'react-bootstrap/helpers'
interface Props {
isLoading?: boolean
}
type BtnProps<As extends React.ElementType = 'button'> = ReplaceProps<
As,
BsPrefixProps<As> & ButtonProps
>
export const Button: React.FC<BtnProps & Props> = ({ isLoading, disabled, ...props }) => {
return <Btn {...props} disabled={isLoading || disabled} />
}
This almost works. The error I got is telling me that ref prop types are wrong:
Types of property 'ref' are incompatible.
...
Type '(instance: HTMLButtonElement | null) => void' is not assignable to type '(instance: Button> | null) => void'.
I stripped most of the error message to get the relevant bit. Do I need to wrap the component in forwardRef for this work?