I want to fetch an rest api data into the react table. How do I set
the row data inside the react table from the value that is got in
componentDidMount()?
Following is my sample code:
constructor() {
super();
this.state = {
data: [],
}
}
componentDidMount() {
fetch('https://facebook.github.io/react-native/movies.json').then((Response) => Response.json()).
then((findresponse) => {
console.log(findresponse.movies)
this.setState({
data: findresponse.movies
})
})
}
render() {
this.state.data.map((dynamicData, key) => {
const data = [{
name: {
this.dynaimcData.title
},
age: {
this.dynamicData.releaseYear
}]
})
const columns = [{
Header: 'Name',
accessor: 'name'
},
{
Header: 'Age',
accessor: 'age'
}
]
return (<ReactTable data: {data} column: {columns}/>)
})
}
data:{data}not bedata={data}?this.state.data.map((dynamicData, key) => {...}should be inside return. You haven't written return statement inside render.