Invalid support type: Chat: type "number" is not valid; it should be a function, usually from React.PropTypes

this is the complete code for the responsive component:

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:

Faulty support type: Chat: prop type is roominvalid; it should be a function, usually from React.PropTypes.

+4
source share
1 answer

Change room: React.PropTypes.Objectto room: React.PropTypes.Object. You made a typo, the property objectshould start with o in lowercase.

+2
source

Source: https://habr.com/ru/post/1651779/


All Articles