Skip to content

Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()? #71

@HugoGresse

Description

@HugoGresse

when using with a simple function component as follow:

                <ScrollableAnchor id={"faq"} >
                    <BlockTitle>
                        FAQ
                    </BlockTitle>
                </ScrollableAnchor>
const BlockTitle = ({ children, ...props }) => {
    const classes = useStyles()

    return (
        <Typography className={classes.title} variant="h2" {...props}>
            {children}
        </Typography>
    )
}

React doesn't like it and report the following warning:
Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

If I use a plain <div> rather than a custom component it work though.

This is maybe linked to the clone element from the ScollableAnchor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions