如何在 react-native pell 富编辑器中设置字符限制?

How to set character limit in react-native pell rich editor?

我想在 richeditor 中设置最大字符长度为 3000。我正在使用 react-native-pell-rich-editor。当用户插入超过 3000 个字符时,所有多余的字符都应自动删除。我收到 html 内容。

那么这个问题有什么解决方案吗?

这是我的代码:

<RichEditor
    disabled={false}
    initialContentHTML={summary}
    style={{
      height: "100%",
      backgroundColor: "white",
      flex: 1,
      paddingTop: 1,
      paddingBottom: 5,
      justifyContent: "center",
      minHeight: "100%",
      minWidth: "100%",
      width: "100%",
    }}
    showsVerticalScrollIndicator={false}
    scrollEnabled={false}
    ref={editor}
    placeholder={"Write summary (Max 3000 char)"}
    onChange={changeHTML}
/>

我的解决方案:

changeHTML= (val) => {
    if(val != this.prevDescVal){
        let rawVal = val;
        if(val.replace(/<[^>]*>/g, '').length > 1500 ){
            this.richtext.current?.setContentHTML('');
            this.richtext.current?.insertHTML(this.prevDescVal);
            this.toast.show({
                text: "Maximum limit 1500",
                type: "failed",
            });
        }else{
            this.prevDescVal = rawVal;
        }
    }
}