DEV Community

Discussion on: Need some help & advice from React.js devs!

Collapse
 
mathewthe2 profile image
Mathew Chan • Edited
const data = response.data.data.map(item=>{ 
  return {Date: item.Date, Company_nm: item.Company}
});
this.setState({data}) ;
Enter fullscreen mode Exit fullscreen mode

I'm only guessing what you want to do here.

Collapse
 
yoqub98 profile image
yoqub98

I somehow get what you did...except this.setState({data});
Then how I am going to be rendering this in my table? Could clarify that part too?

Collapse
 
mathewthe2 profile image
Mathew Chan • Edited

this.setState({data}) is shorthand for this.setState({data: data}), i.e. you assign the value of data to this.state.data. To render the data to your table

render() {
  const {data} = this.state;
  return (
    <table>
    <tr>
      <th>Date</th>
      <th>Company<th/>
    </tr>
    data.map(item=>return(
      <tr>
        <td>{item.Date}</td>
        <td>{item.Company_nm}</td>
      </tr>
    ))
    </table>
  )
}
Enter fullscreen mode Exit fullscreen mode