Draft-js: How to set block data?

Created on 26 Sep 2016  路  7Comments  路  Source: facebook/draft-js

I want to insert a code block and specify the language of the code block like JavaScript for code highlight (I use decorator to make it), but since I use RichUtils.toggleBlockType, how can I add block data on that? Thanks!

Most helpful comment

Any concrete example on how to do this?

All 7 comments

thanks @jan4984 !

Any concrete example on how to do this?

@goddyZhao & @jan4984 could you show us an example of how to use Modifier.setBlockData() ? What is the Map<any,any> and how do we set it?

And can anyone explain why those arguments are used? For instance, why do we need SelectionState in Modifier.setBlockData? What will happen if selection state is greater than the block we want to "tag"? If Modifier is adding block metadata, shouldn't then we pass the ContentBlock instead? And as @promerorgz asked, what is Map<any, any>? What should we pass there, why do we need a Map?

@negyxo that is true, you can modify contentblock directly by using immutable-js API, but you will need lots of codes(about 10 lines I think), Modifier is a just helper class

Any concrete example on how to do this?

here's a good reference of how to use setDataBlock

https://sendgrid.com/blog/how-we-use-draft-js-at-sendgrid/

Was this page helpful?
0 / 5 - 0 ratings