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.

Custom block wrappers not working as in docs

See original GitHub issue

Do you want to request a feature or report a bug? bug

What is the current behavior? I am trying to add a custom id to headers (for a table of contents). I am following the example, and I get an error about this not being defined. I using the exact code as per docs.

What is the expected behavior? props should be passed through to custom wrapper

Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js? Chrome Latest (macOS) draft-js 0.9.1

pasted graphic copy

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
oscarmorrisoncommented, Jan 16, 2017

@aight8 I was able to achieve what I was going for using a custom element:

const HEADERS = {
    'header-one': 'h1',
    'header-two': 'h2',
    'header-three': 'h3',
    'header-four': 'h4',
    'header-five': 'h5',
};

const blockRenderMapGenerator = editorState => {

    let contentState = editorState.getCurrentContent();

    const Header = props => {
        let {key} = props.children;
        let block = contentState.getBlockForKey(key);
        let id = block.getData().get('id');
        let type = block.getType();
        const Tag = HEADERS[type] || 'span';

        return (
            <Tag id={id}>
                {props.children}
            </Tag>
        );
    }

    const blockRenderMap = Immutable.Map({
        'header-one': {
            element: Header
        },

thankyou for you help!

1reaction
aight8commented, Jan 16, 2017

oh I didn’t know that this works. thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Define Blocks | Blockly - Google Developers
Block definitions describe how a block looks and behaves, including the text, the colour, the shape, and what other blocks it can connect...
Read more >
Is there a LaTeX wrapper for use in Google Docs? - TeX
There is a vast number of LaTeX-Lab-like wrappers for Google Docs whose ... As of September 2019 the site is not reachable anymore...
Read more >
Insert smart chips & building blocks in your Google Doc
You can also insert dropdowns, or use building blocks to keep track of projects, ... In Google Docs, you can add and customize...
Read more >
Styles | Block Editor Handbook
They work by adding a className to the block's wrapper. This… ... block style as the one that is recognized as active when...
Read more >
Building Custom Gutenberg Blocks: The Definitive ... - Kinsta
Building Gutenberg blocks can seem daunting at first. But it's not! This in-depth guide will show you how to create your first WP...
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