Skip to content

How to create a "Repeating Container" #367

Answered by cederron
cederron asked this question in Q&A
Discussion options

You must be logged in to vote

Well, seems I have been able to pull this on my own :)
it was simpler than expected.

I modified container initialization, get editor state and inspect the children

  let child: ReactNode = null;
  if(React.Children.count(children) > 0){
    child = React.Children.only(children);
  }

  const { enabled } = useEditor((state) => ({
    enabled: state.options.enabled,
  }));

now in the render function

{
          child != null ? ( enabled ? child  : data.map((item) => child)) : <span>No child</span>
 }

Still not finished, but seems i can get there from here, now i guess i will have to fiddle with React.createElement or something to pass the array element as prop to the child component

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@cederron
Comment options

@cederron
Comment options

@heyjaypray
Comment options

@cederron
Comment options

@heyjaypray
Comment options

Answer selected by cederron
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants