Skip to content
Discussion options

You must be logged in to vote

HELL yes I have a solution for you.

You need to import all of your React block components only at the top level where the first "blocks" are rendered, and then pass them through each additional layer of blocks as either props or with context. But the trick is to only import them once, at the top level, and then needle them through the rest of the way. So say you have a RenderBlocks component or similar. THAT component needs to accept your block components as props or retrieve them via context.

We had to do this internally in Payload with our field components themselves, because fields can render other fields and then boom - recursion. It's a common problem with programming in general!

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
2 replies
@joecaraccio
Comment options

@joecaraccio
Comment options

Answer selected by zubricks
Comment options

You must be logged in to vote
4 replies
@joecaraccio
Comment options

@ozbeksu
Comment options

@andwrobs
Comment options

@andwrobs
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants