markdown-to-jsx icon indicating copy to clipboard operation
markdown-to-jsx copied to clipboard

Creating a ref when overriding a component

Open ben4d85 opened this issue 4 years ago • 1 comments

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 avatar Jan 08 '20 13:01 ben4d85

Any updates on this? Same requirement.

samupra avatar Jun 04 '20 14:06 samupra