Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140390

How can I orderBy a component in React

$
0
0

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 ?


Viewing all articles
Browse latest Browse all 140390

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>