Мне нужно сделать эту страницу автоматически обновленной, сделать вызов ajax для бэкэнда 3 минуты как, как настроить это? Я думаю, что задан интервал в ajax, чтобы он автоматически вызывался каждые 3 минуты? Есть ли способ реализовать это? Или есть лучшее решение для реализации этого?Как сделать автоматическое обновление ajax в реакции js
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>
);
}
}
Для обработки сложных взаимодействий, вы можете посмотреть в [перевождь] (https://github.com/reactjs/redux), [реакция-редукция] (https://github.com/reactjs/react-redux) и [redux-thunk] (https://github.com/gaearon/redux-thunk). –