Обновление свойства состояния data
значение в методе компонента реагирования componentDidMount
без обновления данных таблицы реакции.
вызов getData в конструкторе работает нормально.
App.js
class App extends React.Component {
constructor() {
super();
this.state = {
data: []
};
}
getData() {
var MOUNTAINS = [
{name: "Kilimanjaro", height: 5895, country: "Tanzania"},
{name: "Everest", height: 8848, country: "Nepal"},
{name: "Mount Fuji", height: 3776, country: "Japan"},
{name: "Mont Blanc", height: 4808, country: "Italy/France"},
{name: "Vaalserberg", height: 323, country: "Netherlands"},
{name: "Denali", height: 6168, country: "United States"},
{name: "Popocatepetl", height: 5465, country: "Mexico"}
];
return MOUNTAINS;
}
componentDidMount() {
this.setState({ data : this.getData()}, () => {
console.table(this.state.data);
});
}
render() {
const { data } = this.state;
return <T data={data} />;
}
}
T.js
export default class T extends Component {
constructor(props) {
super(props);
debugger;
this.state = {
data: props.data
};
}
render() {
return (
<div>
<ReactTable
data={this.state.data}
columns={[{
Header: "Name",
accessor: "name"
},{
Header: "Height",
accessor: "height"
},{
Header: "Country",
accessor: "country"
}]}
defaultPageSize={10}
className="-striped -highlight"
/>
<br />
</div>
);
}
}