最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - Gutenberg blocks error: Each child in a list should have a unique "key" prop

programmeradmin1浏览0评论

I am learning building custom Gutenberg blocks in WordPress, Since reactjs is a new language to me, I would appreciate some help with the error below. Its a warning in the console

Warning: Each child in a list should have a unique "key" prop. See  for more information.
    in edit (created by Edit)
    in Edit (created by WithToolbarControls(Edit))

Below is a screenshot.

My Gutenberg javascript code is as below

const { registerBlockType } = wp.blocks;

registerBlockType('gutenberg-mwako/section', {

    title: 'Section',

    category: 'layout',

    attributes: {},

    edit() {
        return([
            <section>
                <div className="container">
                    <h2>Title here</h2>
                </div>
            </section>
        ])
    },

    save() {
        return(
            <section>
                <div className="container">
                    <h2>Title here</h2>
                </div>
            </section>
        )
    }
});

I am learning building custom Gutenberg blocks in WordPress, Since reactjs is a new language to me, I would appreciate some help with the error below. Its a warning in the console

Warning: Each child in a list should have a unique "key" prop. See https://fb.me/react-warning-keys for more information.
    in edit (created by Edit)
    in Edit (created by WithToolbarControls(Edit))

Below is a screenshot.

My Gutenberg javascript code is as below

const { registerBlockType } = wp.blocks;

registerBlockType('gutenberg-mwako/section', {

    title: 'Section',

    category: 'layout',

    attributes: {},

    edit() {
        return([
            <section>
                <div className="container">
                    <h2>Title here</h2>
                </div>
            </section>
        ])
    },

    save() {
        return(
            <section>
                <div className="container">
                    <h2>Title here</h2>
                </div>
            </section>
        )
    }
});
Share Improve this question asked Mar 12, 2020 at 10:03 muya.devmuya.dev 1251 gold badge1 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You need to provide a key for the section element in your edit() function (which returns an array of elements):

edit() {
    return([
        <section key="my-key">
            <div className="container">
                <h2>Title here</h2>
            </div>
        </section>
    ])
},
发布评论

评论列表(0)

  1. 暂无评论