From eef1946243b6fa35b3022ea184b8acebe45df8dc Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 1 Aug 2018 18:32:21 +0200 Subject: [PATCH] Used setState callback to ensure no race conditions occur --- src/short-urls/ShortUrlVisits.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/short-urls/ShortUrlVisits.js b/src/short-urls/ShortUrlVisits.js index c5889e58..fcc8255a 100644 --- a/src/short-urls/ShortUrlVisits.js +++ b/src/short-urls/ShortUrlVisits.js @@ -22,11 +22,11 @@ const MutedMessage = ({ children }) => export class ShortUrlsVisits extends React.Component { state = { startDate: undefined, endDate: undefined }; - loadVisits = (dates = {}) => { + loadVisits = () => { const { match: { params } } = this.props; this.props.getShortUrlVisits(params.shortCode, mapObjIndexed( value => value && value.format ? value.format('YYYY-MM-DD') : value, - { ...this.state, ...dates } + this.state )) }; @@ -150,19 +150,13 @@ export class ShortUrlsVisits extends React.Component { { - this.setState({ startDate: date }); - this.loadVisits({ startDate: date }); - }} + onChange={date => this.setState({ startDate: date }, () => this.loadVisits())} className="short-url-visits__date-input" /> { - this.setState({ endDate: date }); - this.loadVisits({ endDate: date }); - }} + onChange={date => this.setState({ endDate: date }, () => this.loadVisits())} className="short-url-visits__date-input" />