vigetlabs / colonel-kurtz

A Block Editor
MIT License
319 stars 33 forks source link

Ways to pass props/context to blocktypes #154

Open lanthias opened 5 years ago

lanthias commented 5 years ago

Hi there,

I'm trying to create a blockType which makes use of data and functions from a React context. I could either implement this context inside the blockType itself, or would be happy to pass the data from the context in as props to the blockType from the top-level component.

It seems if I implement a context inside a blockType, it is empty (even if I nest some components), and I can't figure out the right pattern for passing props into a blockType. I'm presuming the right pattern is not to use content to pass in things like API functions and data which won't be displayed to the user.

Apologies if I am missing something very obvious here, but what is the right pattern to pass props/context into a BlockType?

Thanks!

cwmanning commented 5 years ago

Hey, @lanthias. I was working on something similar in #141, though I haven't gotten back to it yet. Do you think that approach could help? The general idea is something like this:

let editor = new ColonelKurtz({
  // ...
  blockTypeOptions: {
    youtube: { name: 'Chris' }
  }
})

In this example, youtube is the block type key, and the object value would be passed as props to the component.

lanthias commented 5 years ago

Hi @cwmanning - yes, that would be excellent! Exactly what I'm looking for.

Considering this, I think the part about not being able to use context inside a block is perhaps a separate ticket / outside the scope of this issue.