I'm trying to convert my React app (create-react-app) to use Typescript and I've hit a hurdle with a component that uses render props.
Here's a simplified version which still has the error...
import React from 'react'
type Props = {
fullWidth?: boolean,
renderRightSection?: React.ReactNode
}
const Component = React.forwardRef<HTMLInputElement, Props>((props, ref) => {
let {fullWidth, renderRightSection, ...inputProps} = props
return (
<InputWrapper fullWidth={props.fullWidth}>
<input {...inputProps} ref={ref} />
{renderRightSection && renderRightSection()}
</InputWrapper>
)
})
The error is with the renderRightSection() bit and looks like this:
let renderRightSection: string | number | true | {} | React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | ... | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<...>)> | React.ReactNodeArray | React.ReactPortal
This expression is not callable.
No constituent of type 'string | number | true | {} | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | ReactNodeArray | ReactPortal' is callable.ts(2349)
Any help would really be appreciated.
Edit:
To show how I am using the component in a form:
<Textbox
name="username"
type="text"
fullWidth={true}
placeholder="Choose a Username"
renderRightSection={() => (
<TextboxBadge>
{usernameAvailable && <span>Available</span>}
{!usernameAvailable && <span>Taken</span>}
</TextboxBadge>
)}
/>
Edit:
And here's what it's used for, rendering a block of JSX on the right hand side of the textbox.
