removed unnecessary local page state

This commit is contained in:
Florian Scholdei
2019-04-17 15:46:49 +02:00
parent 9bc9e133cc
commit 53ce955f66
3 changed files with 21 additions and 70 deletions

View File

@@ -45,34 +45,22 @@ type Props = {
fetchUsersByLink: (link: string) => void
};
type State = {
page: number
};
class Users extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
page: -1
};
}
class Users extends React.Component<Props> {
componentDidMount() {
const { fetchUsersByPage, usersLink, page } = this.props;
fetchUsersByPage(usersLink, page, this.getQueryString());
this.setState({ page: page });
}
componentDidUpdate = (prevProps: Props) => {
const { list, page, location, fetchUsersByPage, usersLink } = this.props;
if (list && page) {
const { list, page, loading, location, fetchUsersByPage, usersLink } = this.props;
if (list && page && !loading) {
const statePage: number = list.page + 1;
if (
page !== this.state.page ||
page !== statePage ||
prevProps.location.search !== location.search
) {
fetchUsersByPage(usersLink, page, this.getQueryString());
this.setState({ page: page });
}
}
};