Used setState callback to ensure no race conditions occur

This commit is contained in:
Alejandro Celaya 2018-08-01 18:32:21 +02:00
parent 0b15fba640
commit eef1946243

View file

@ -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 {
<DateInput
selected={this.state.startDate}
placeholderText="Since"
onChange={date => {
this.setState({ startDate: date });
this.loadVisits({ startDate: date });
}}
onChange={date => this.setState({ startDate: date }, () => this.loadVisits())}
className="short-url-visits__date-input"
/>
<DateInput
selected={this.state.endDate}
placeholderText="Until"
onChange={date => {
this.setState({ endDate: date });
this.loadVisits({ endDate: date });
}}
onChange={date => this.setState({ endDate: date }, () => this.loadVisits())}
className="short-url-visits__date-input"
/>
</form>