Skip to content

How to programmatically insert a component #639

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

You must be logged in to vote

I think I've got it

  const handleKey = useCallback(
    e => {
      if (e.key === 'Enter') {
        e.stopPropagation()
        const a = query.node(id).ancestors()
        const newPara = query.parseReactElement(<Text text="new para" />).toNodeTree()
        actions.addNodeTree(newPara, a[a.length - 1])
      }
    },
    [actions, id, query]
  )

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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