这个React错误是什么意思? “期望onBeforeMountComponent()parent和onSetChildren()保持一致”

时间:2017-03-01 16:00:18

标签: javascript reactjs material-ui

将材质UI与此示例一起使用React组件:

const React = require('react');
const DropDownMenu = require('material-ui/DropDownMenu').default;
const MenuItem = require('material-ui/MenuItem').default;

const MyDropDown = React.createClass({
    getDefaultProps: function() {
        return {
            onChange: () => {},
            items: []
        };
    },

    getInitialState: function() {
        return {
            value: undefined
        };
    },

    render: function() {
        const {
            state: {value},
            props: {items, id}
        } = this;

        return React.createElement(DropDownMenu, {
            id,
            maxHeight: 300,
            onChange: (event, index, value) => {
                this.setState({value});
            },
            value: typeof value === 'undefined'
                    ? items[0].value
                    : value,
            children: items.map((item, key) => (
                React.createElement(MenuItem, {
                    value: item.value,
                    primaryText: item.label,
                    key
                })
            ))
        });
    }
});

当我选择或悬停其中一个项目时,我收到此错误。

Exception thrown by hook while handling onSetChildren:
Invariant Violation: Expected onBeforeMountComponent() parent
and onSetChildren() to be consistent (74 has parents 41 and 73).

这可以在任何具有可点击子项的Material UI组件中重现。 错误的阅读材料令人沮丧地稀疏。 此错误意味着什么,为什么会发生?

0 个答案:

没有答案