繁体   English   中英

当从 tinyMCE onAction 方法调用 setState 时,State 未更新

[英]State not updated when setState is called from tinyMCE onAction method

我正在研究 react 和 tinymce 中的图书创建者。 允许用户在 canvas 上创建多个文本块并用文本填充它们。

当使用 onClick 方法创建新文本块的按钮在外部编辑器中调用时,一切正常,就像典型的那样。

当我尝试添加工具栏按钮时问题开始了:

    setup: (editor) => {
        editor.ui.registry.addButton("AddNew", {
        text: "Add new",
        onAction: (buttonApi) => addTextBlock()
        });
    },

它工作一次。 It creates textBlock object by updating the state object but consecutive clicks on this button reset state to initial value (empty list) and add again one object.

从放置在编辑器外部的按钮执行的相同代码正确创建了点击量的文本块。

我在控制台中没有错误或相关警告。

我也有同样的问题,然后我用以下代码解决了这个问题:

setup: (editor) => {
    let self = this;
    editor.ui.registry.addButton('customButton', {
        text: 'Button',
        tooltip: 'Insert/edit image',
        onAction: function(){
            self.setState({click:true});
        }
    });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM