move sort to render.

This commit is contained in:
Jason Schwarzenberger 2020-11-03 16:30:22 +13:00
parent 4f90671cec
commit 0567cdfd9b

View File

@ -23,10 +23,6 @@ class Feed extends React.Component {
console.log('updated:', updated); console.log('updated:', updated);
const { stories } = result; const { stories } = result;
if (stories) {
stories.sort((a, b) => b.date - a.date);
}
this.setState({ stories }); this.setState({ stories });
localStorage.setItem('stories', JSON.stringify(stories)); localStorage.setItem('stories', JSON.stringify(stories));
@ -54,6 +50,10 @@ class Feed extends React.Component {
const stories = this.state.stories; const stories = this.state.stories;
const error = this.state.error; const error = this.state.error;
if (stories) {
stories.sort((a, b) => b.date - a.date);
}
return ( return (
<div className='container'> <div className='container'>
<Helmet> <Helmet>