Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditorJs warning "«blocks.stretchBlock()» is deprecated and will be removed in the next major release. Please use the «BlockAPI» instead."

I'm using EditorJs but it is giving me this warning in the console

«blocks.stretchBlock()» is deprecated and will be removed in the next major release. Please use the «BlockAPI» instead.

How can I use «BlockAPI» in EditorJs?

Here is my EditorJs init:

const editor = new EditorJS({
  tools: {
    header: Header,
    list: List,
    image: Image,
    embed: {
      class: Embed,
      config: {
        services: {
          youtube: true
        }
      }
    },
  },
})
like image 346
RiadSaidur Avatar asked Oct 11 '25 22:10

RiadSaidur


1 Answers

Block API is passed via constructor props in block prop. You have to get it from there and set it to your block's property.

It should look something like this:

class CustomBlock {
  private data;
  private block;

  constructor({
    data,
    block
  }) {
    this.data = data;
    this.block = block;
  }

  toggleStretched() {
    this.block.stretched = !!this.data.stretched;
  }

  // Rest of the block implementation
}

It seems that the official docs aren't up-to-date, however I found this file with a description of Block API.

like image 189
Konrad Kalemba Avatar answered Oct 14 '25 10:10

Konrad Kalemba