Paulo Rodrigues
Paulo Rodrigues

Reputation: 407

React 'props' is not defined

can someone tell me why props is not defined? in this code, I need to pass this way to call another component,

Look at <SC.ButtonPlus>

I am new with react can anyone help me with it??

React code below:

class ViewNotas extends Component {
  constructor(props) {
    super(props);

    this.state = {
      open: [],
      newContact: false,
      edit: [],
      loading: false,
    };

    this.handleOpen = this.handleOpen.bind(this);
    this.setNewContact = this.setNewContact.bind(this);
  }

  setNewContact(set) {
    this.setState({
      newContact: set,
    });
  }

  handleOpen(id, isOpen) {
    if (!isOpen) {
      this.setState({ open: this.state.open.concat(id) });
    } else {
      this.setState({
        open: this.state.open.filter((objectId) => id !== objectId),
      });
    }
  }

  render() {
    let data = this.props.data;

    return (
      <Modal open={this.props.open} visible={this.props.visible}>
        <SC.Container>
          <SC.Header>
            <SC.Title>Notas</SC.Title>
            <SC.ButtonPlus onClick={() => props.setNewContact(true)}>
              <GoPlus size="24px" color="#FFF" />
            </SC.ButtonPlus>

Upvotes: 0

Views: 491

Answers (2)

Hemant Parashar
Hemant Parashar

Reputation: 3774

The issue tis that you're accessing the method on the props

                              /* change this  */
 <SC.ButtonPlus onClick={() => this.setNewContact(true)}>
    <GoPlus size="24px" color="#FFF" />
  </SC.ButtonPlus>

Hope this helps !

Upvotes: 0

ktowen
ktowen

Reputation: 336

This line

<SC.ButtonPlus onClick={() => props.setNewContact(true)}>

shoud be

<SC.ButtonPlus onClick={() => this.setNewContact(true)}>

Upvotes: 2

Related Questions