Skip to content

Commit

Permalink
Dont use .finally
Browse files Browse the repository at this point in the history
  • Loading branch information
Pav0l committed Sep 18, 2019
1 parent 4661ba7 commit 18bc074
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/components/pages/Dashboard/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import { getfarmerStatisticsHandler } from '../../../utils/handlers/farmerHandle
const Dashboard = ({ farmers, history }) => {
const [data, setData] = useState([]);
const [farmersStatistic, setFarmersStatistic] = useState({});
const [farmersStatisticsLoading, setFarmersStatisticsLoading] = useState(true);
const [farmersStatisticsLoading, setFarmersStatisticsLoading] = useState(
true
);

const Title = <Header as="h1">All Farmers</Header>;

Expand All @@ -33,12 +35,14 @@ const Dashboard = ({ farmers, history }) => {
setFarmersStatisticsLoading(true);
getfarmerStatisticsHandler()
.then(res => {
setFarmersStatistic(res)
setFarmersStatistic(res);
setFarmersStatisticsLoading(false);
})
.catch(error => {
toast.error(error.message);
})
.finally(() => setFarmersStatisticsLoading(false));
setFarmersStatisticsLoading(false);
});
// .finally(() => setFarmersStatisticsLoading(false));
}, []);

const renderFarmersStatistic = () => {
Expand All @@ -56,10 +60,7 @@ const Dashboard = ({ farmers, history }) => {

if (Object.keys(farmersStatistic).length === 0) {
return (
<Segment
secondary
style={{ textAlign: 'center' }}
>
<Segment secondary style={{ textAlign: 'center' }}>
Failed to retreive farmer statistics
</Segment>
);
Expand Down

0 comments on commit 18bc074

Please sign in to comment.