I am rendering a component that display an array and I want them to be order by the last entry.
I've tried to do a function outside the render that orderBy and include it in the component but it's not mounting correctly.
orderBy() {
let data = this.state;
data.data.sort((a, b) => {return a.published_on - b.published_on}).map((data) =>{return data})
}
render() {
const { loading, data } = this.state;
return (
<div className="list">
<Table rowKey="ref" loading={loading} dataSource={data.data} size="large" />
</div>
);
}
I want the Table component to be order on the loading by data.data.published_on.
What is the correct way to do that in React ?