0

Am new to react JS I have encountered an error while pushing data:

Uncaught TypeError: Cannot read property 'forEach' of undefined

this.props.clist.forEach(function(company) {
companies.push( <Company company={company} onCompanyDelete={that.handleCompanyRemove} /> );
});

complete code : https://codepen.io/prashanthHarish/pen/jxVWGE (line 49)

example from http://tuts-javascript.appspot.com/reactjs-add-remove-table-row

1
  • Did you try accessing like “that.props”? Commented May 11, 2018 at 11:07

2 Answers 2

0

you dont have "clist" prop passed to CompanyList component. pass that prop then you can use it

Sign up to request clarification or add additional context in comments.

1 Comment

With demonstration will be helpful.
0

if you see your handelNewRowSubmission function

handleNewRowSubmit: function( newcompany ) {
      this.setState( {companylist: this.state.companylist.concat([newcompany])} );
    }

you are using concat which will just concat. if you need a list of array then you save the value to some variable and push new value to it and then assign it to companyList state.

var compList = [];
compList = this.state.companylist;
compList.push(newcompany);
this.setState({companylist : compList});

Comments

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.