question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

anchor-plugin not inserting an anchor-tag

See original GitHub issue

I have added the anchor-plugin to my editor as documented. When I add a link, it appears to get added correctly to the editorState, however the generated html does not have the <a> tag. What am I missing? My code is shown below:

const linkPlugin = createLinkPlugin();
const inlineToolbarPlugin = createInlineToolbarPlugin({
    structure: [
        BoldButton,
        ItalicButton,
        UnderlineButton,
        CodeButton,
        linkPlugin.LinkButton
    ]
});
const { InlineToolbar } = inlineToolbarPlugin;
const plugins = [inlineToolbarPlugin, linkPlugin];

export class TextEdit extends React.Component {
    ...

    render() {
        const { classes } = this.props;

        return (
            <div className={classes.editor}>
                <Editor
                    editorState={this.state.editorState}
                    onChange={this.onChange}
                    onBlur={this.onBlur}
                    plugins={plugins}
                    ref={element => { this.editor = element; }}
                />
                <InlineToolbar />
            </div>
        );
    }

    ...
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nareshbhatiacommented, Jan 7, 2018

I have finally been able to solve this!

TL;DR: I needed to initialize the editorState from props. If I do this in componentDidMount(), then the decorators are lost. However if I do this initialization in the constructor (where props are still available), everything works just fine.

Old Code

constructor(props) {
    super(props);
    ...
    this.state = {
        editorState: EditorState.createEmpty()
    };
}

componentDidMount() {
    const { html } = this.props;
    this.setState({
        editorState: EditorState.createWithContent(stateFromHTML(html))
    });
}

New Code

constructor(props) {
    super(props);
    ...
    const { html } = this.props;
    this.state = {
        editorState: EditorState.createWithContent(stateFromHTML(html))
    };
}
0reactions
stale[bot]commented, Dec 12, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No ability to add anchor links? - WordPress.org
I am trying to create anchors to link within my website. This is usually done by adding text to the Advanced box in...
Read more >
TinyMCE links plugin doesn't render anchor links in the content
I want the link to be showed as tag so it can be clickable. I have used link plugin commands like: tinymce.init({ selector:...
Read more >
How to Create Anchor Links in WordPress (3 Easy Methods)
Highlight the header you want to link it up to. Then click on “Insert” from the button at the top and select “Anchor.”...
Read more >
How to "Easily" Add Anchor Links in WordPress (Step by Step)
Creating an anchor link. First you need to select the text that you want to link and then click on the insert link...
Read more >
Add Anchor Tags To Jump To Specific Location On A Page
With the Rich Text editor, you can place anchors in your posts. If you prefer to use HTML to code the anchor tags,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found