首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SlateJS + redux

SlateJS + redux
EN

Stack Overflow用户
提问于 2018-11-13 07:38:29
回答 1查看 667关注 0票数 1

我想将SlateJS编辑器的值存储在redux中而不是状态中,但是当我更改hasLinks方法时,我立即收到一个崩溃消息,声明:

TypeError:无法读取未定义的属性“内联”

编辑器的 Method

代码语言:javascript
复制
hasLinks = () => {
    // const { value } = this.state // Original
    const { value } = this.props // Update for redux
    // Alternative attempts
    // const { value }  = this.props.editorValue
    // const  value  = this.props.editorValue
    // const { value }  = this.props.editorValue
    // const value  = Object.assign({}, this.props.editorValue)
    // const value  = Value.fromJSON(Object.assign({}, this.props.editorValue))
    return value.inlines.some(inline => inline.type == 'link') // Crashes on this line
    // return value && value.inlines && value.inlines.some(inline => inline.type == 'link') // Alternative attempt that avoids initial crash, but creates a memory overload when editor is accessed much
}

Redux商店

代码语言:javascript
复制
const initialState = {
    editorValue: Value.fromJSON(initialValue),
}

初始状态

代码语言:javascript
复制
{
    "document": {
        "nodes": [{
                "object": "block",
                "type": "paragraph",
                "nodes": [{
                    "object": "text",
                    "leaves": [{
                        "text": "By default, pasting content into a Slate editor will use the content's plain text representation. This is fine for some use cases, but sometimes you want to actually be able to paste in content and have it parsed into blocks and links and things. To do this, you need to add a parser that triggers on paste. This is an example of doing exactly that!"
                    }]
                }]
            },
            {
                "object": "block",
                "type": "paragraph",
                "nodes": [{
                    "object": "text",
                    "leaves": [{
                        "text": "Try it out for yourself! Copy and paste some rendered HTML content (not the source code) from another site into this editor."
                    }]
                }]
            }
        ]
    }
}

可以帮助我理解为什么这不起作用,以及我可以做些什么来更新以解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2019-10-02 15:33:50

这已经有一年多的历史了,但问题是const { value } = this.props要求props具有一个名为value的属性。你的看起来像editorValue。一个常见的问题是,对象析构只使用相同的属性名称(即不能用不同的名称重新分配)(以这种最小的形式)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53276041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档