/
githubmirror
/
redux
Обзор
Документация
Войти
/
githubmirror
/
redux
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/real-world/src/components/List.js
70 строк
1 KB
Tim Dorr
Format the examples
20 мар 2024, 19:52
Не верифицирован
20 мар 2024, 19:52
3085048
Код
Авторство
О чём код?
/* eslint-disable no-undef */ import React, { Component } from 'react' import PropTypes from 'prop-types' export default class List extends Component { static propTypes = { loadingLabel: PropTypes.string.isRequired, pageCount: PropTypes.number, renderItem: PropTypes.func.isRequired, items: PropTypes.array.isRequired, isFetching: PropTypes.bool.isRequired, onLoadMoreClick: PropTypes.func.isRequired, nextPageUrl: PropTypes.string } static defaultProps = { isFetching: true, loadingLabel: 'Loading...' } renderLoadMore() { const { isFetching, onLoadMoreClick } = this.props return ( <button style={{ fontSize: '150%' }} onClick={onLoadMoreClick} disabled={isFetching} > {isFetching ? 'Loading...' : 'Load More'} </button> ) } render() { const { isFetching, nextPageUrl, pageCount, items, renderItem, loadingLabel } = this.props const isEmpty = items.length === 0 if (isEmpty && isFetching) { return ( <h2> <i>{loadingLabel}</i> </h2> ) } const isLastPage = !nextPageUrl if (isEmpty && isLastPage) { return ( <h1> <i>Nothing here!</i> </h1> ) } return ( <div> {items.map(renderItem)} {pageCount > 0 && !isLastPage && this.renderLoadMore()} </div> ) } }