[英]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.