简体   繁体   English

失败的道具类型:聊天:道具类型`房间`无效; 它必须是一个函数,通常来自React.PropTypes

[英]Failed prop type: Chat: prop type `room` is invalid; it must be a function, usually from React.PropTypes

this is the full code for the react component: 这是react组件的完整代码:

import React from 'react';

class Chat extends React.Component {
    handleSubmit(e) {
        e.preventDefault();

        this.props.addMessage(this.props.room.id, this.state.message);

        this.setState({ message: '' });
    }

    handleMsgChange(event) {
        this.setState({ message: event.target.value });
    }

    render() {
        return (
            <div>
                <div>{this.props.room.messages.toString()}</div>
                <form onSubmit={this.handleSubmit}>
                    <input
                        onChange={this.handleMsgChange}
                        value={this.state.message}
                        type="text" placeholder="Your message"
                    />
                    <input type="submit" value="Send" />
                </form>
            </div>
        );
    }
}

Chat.propTypes = {
    addMessage: React.PropTypes.func,
    room: React.PropTypes.Object,
};

export default Chat;

and I get the error: 我收到错误:

Failed prop type: Chat: prop type room is invalid; 支柱类型失败:聊天:道具类型room无效; it must be a function, usually from React.PropTypes. 它必须是一个函数,通常来自React.PropTypes。

Change room: React.PropTypes.Object to room: React.PropTypes.object . 更改room: React.PropTypes.Objectroom: React.PropTypes.object You've made a typo, object property should start with o in lowercase. 你犯了一个拼写错误, object属性应该以小写字母o开头。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:失败的道具类型:游戏:道具类型`游戏`无效; 它必须是一个函数,通常来自React.PropTypes - Warning: Failed prop type: Game: prop type `game` is invalid; it must be a function, usually from React.PropTypes 它必须是一个函数,通常来自 React.PropTypes - it must be a function, usually from React.PropTypes 应用:道具类型“商店”无效; 它必须是一个函数,通常来自“ prop-types”包,但收到了“ undefined” - App: prop type `store` is invalid; it must be a function, usually from the `prop-types` package, but received `undefined` React-(嵌套)道具类型无效; 它必须是一个函数 - React - (nested) prop type is invalid; it must be a function React PropTypes导入类。 道具类型无效 - React PropTypes import class. Prop type is invalid 反应警告:失败的道具类型:提供的“对象”类型的无效道具 - React Warning: Failed prop type: Invalid prop of type `Object` supplied 道具类型失败:类型为“函数”的无效道具“className” - Failed prop type: Invalid prop `className` of type 'function' react-instantsearch-dom:: 道具类型失败:提供给“Hits”的“object”类型的无效道具“hitComponent”,预期为“function” - react-instantsearch-dom:: Failed prop type: Invalid prop `hitComponent` of type `object` supplied to `Hits`, expected `function` React / Redux:失败的prop类型-无效的prop对象 - React/Redux: Failed prop type - Invalid prop object 失败的道具类型:提供给“重定向”的无效道具“到” - Failed prop type: Invalid prop `to` supplied to `Redirect`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM