Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

95
Visualizações
How to externally edit SlateJS editor values

I'm recreating Discord chat. I'm using SlateJS to achieve this.

I have many editors displayed on the page, and I have an Emoji Button. I'd like to be able to externally edit the value of the editors, so when a click on an emoji, the name of it is inserted as a text.

I've tried using useSlate to get the current editor but I'm receiving an error which warns that I can't use the hook outside the context of the editor.

I've tried to ref the Editable component.

And lastly, I've also tried catching an externally changed string state with an useEffect but this doesn't work either, since it changes the value the first time but then doesn't work anymore (and "Modified main element" is displayed in the console).

  useEffect(() => {
    if(editValue){
      Transforms.delete(editor, {
        at: {
          anchor: SlateEditor.start(editor, []),
          focus: SlateEditor.end(editor, []),
        },
      });
      editor.insertFragment(initialTextFunc(editValue));
    }
  }, [editValue, editor]);

...

const initialTextFunc: (initialText: string) => Descendant[] = (initialText: string) => {
  return [{
    type: 'paragraph',
    children: [
      {
        text: initialText,
      },
    ],
  }]
}

I've asked in the Slate's slack but haven't receive any response.

Does anyone have a clue of how to achieve this?

Thanks in advance!

almost 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda