0

Already done

  1. npm install -save prop-types
  2. import PropTypes from 'prop-types';
  3. npm install --save react-router
  4. import {Router, Route, Link} from 'react-router';

I have done everything but I can not do it.

ContactCreate.class

import React from 'react';
import PropTypes from 'prop-types';
import { Router, Route, Link } from 'react-router';

/*skip*/

ContactCreate.propTypes ={
    onCreate : React.PropTypes.func
};
    

package.json

enter image description here

I tried everything that other people have put into the solution but the result was the same. There seems to be no problem with the code, but I do not know what the problem is.

Contact.js

constructor(props) {
    super(props);
    this.state = {
    /*skip*/
    this, handleCreate = this.handleCreate.bind(this);
}

handleCreate(contact) {
    this.setState({
        contactData: update(this.state.contactData, { $push: [contact] })
    });
}

/*skip*/

render() {
/*skip*/
    return (
        <div>
            <h1>Contacts</h1>
            <input
                name="keyword"
                placeholder="Search"
                value={this.state.keyword}
                onChange={this.handleChange}
            />
            <div>{mapToComponents(this.state.contactData)}</div>
            <ContactDetails
                isSelected={this.state.selectedKey != -1}
                contact={this.state.contactData[this.state.selectedKey]}
            />
            <ContactCreate
                onCreate={this.handleCreate}
            />
        </div>
    );
}

1 Answer 1

1

PropTypes is imported from a separate package and hence shouldn't be used like React.PropTypes.func, but PropTypes.func

import React from 'react';
import PropTypes from 'prop-types';
import { Router, Route, Link } from 'react-router';

...

ContactCreate.propTypes ={
    onCreate : PropTypes.func
};
Sign up to request clarification or add additional context in comments.

4 Comments

The following error occurs ==>> ReferenceError: handleCreate is not defined
is handleCreate defined in some part of your code, where exactly is this error pointing
Please confirm that you just posted.
You have a typo here this, handleCreate = this.handleCreate.bind(this); also can you point out where exactly is the error pointing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.