Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

React | ForwardedRef using React.Component

$
0
0

I'm creating a custom component in React, and I need to export it using forwardedRef. But when I try, this error occurs:

error

my code:

export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>{  ref?: React.RefObject<HTMLButtonElement>;}class Button extends React.Component<ButtonProps> {  render() {    const {      ref,      children,      ...otherProps    } = this.props;    return (<button         {...otherProps}         ref={ref}>        {children}</button>    )  }}const ButtonForwarded = React.forwardRef<ButtonProps>((props, ref) => <Button {...props} ref={ref} /> );ButtonForwarded.displayName = 'Button';export default ButtonForwarded;

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>