Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a ref when overriding a component #282

Open
ben4d85 opened this issue Jan 8, 2020 · 1 comment
Open

Creating a ref when overriding a component #282

ben4d85 opened this issue Jan 8, 2020 · 1 comment

Comments

@ben4d85
Copy link

ben4d85 commented Jan 8, 2020

When overriding a component, is there a way to generate a ref?

Context: I have generated a TOC from the h2s in my markdown file. Now I would like to create a feature that scrolls to the corresponding heading in the document when the TOC is clicked. I read ref is the way to go, so now I am trying to add refs to all h2s.

I have tried the below, but ref is not included int he resulting HTML? ("test" is, so I know the rest is working fine)

<Markdown
    children={md}
    options={{
        forceBlock: true,
        overrides: {
            h2: {
                component: Heading,
            }
        },
    }}
/>
export class Heading extends Component {
    render() {
        return (
            <h2 
                id={this.props.id}
                ref={this.props.id}
                test="test"
            >
                {this.props.children}
            </h2>
        );
    };
}
@ben4d85 ben4d85 changed the title Creating a ref when overriding component Creating a ref when overriding a component Jan 8, 2020
@samupra
Copy link

samupra commented Jun 4, 2020

Any updates on this? Same requirement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants