I need to make this page auto refresh, make the ajax call to the backend 3 mins like, how to setup this? What I am thinking is set a interval in ajax, make it automatically call every 3 mins? Is there any way to implement this? Or there is any better solution to implement this?
export default class InventoryLevelReport extends React.Component {
constructor() {
super();
this.state = {
data: [
{
sku: null,
inventoryCount: 0
}
],
url: '/mft/api/reports/inventory-view'
};
}
sortByCount() {
this.setState({data: _.orderBy(this.state.data, (i) => i.inventoryCount)});
}
componentDidMount() {
ajax(this.state.url, {
success: data => {
console.log(data);
this.setState({data: data.data});
}
});
}
render() {
const buttonStyle = {
position: 'relative',
float: 'right'
};
return <div className="content">
<Button style={buttonStyle} onClick={() => this.sortByCount()}>Sort</Button>
<div>
<Table tableType='bordered'>
<th>SKU</th>
<th>Count</th>
<tbody>
{this.state.data.map((data, i) => <InventoryTableRow data={data} key={i} />)}
</tbody>
</Table>
</div>
</div>;
}
}
class InventoryTableRow extends React.Component {
render() {
return (
<TableRow>
<TableColumn>{JSON.stringify(this.props.data.sku).split('"').join('')}</TableColumn>
<TableColumn>{JSON.stringify(this.props.data.inventoryCount)}</TableColumn>
</TableRow>
);
}
}