Skip to content

Instantly share code, notes, and snippets.

@bogdanq
Last active September 21, 2020 19:21
Show Gist options
  • Save bogdanq/47b263d6a07d956de5487ecba210742a to your computer and use it in GitHub Desktop.
Save bogdanq/47b263d6a07d956de5487ecba210742a to your computer and use it in GitHub Desktop.
// test https://github.com/bogdanq/jest-testing/blob/master/src/components/testing-library/components/conditional-list/conditional-list.spec.js
import React from 'react'
import { Spiner } from '@ui'
export const ConditionalList = ({ data, renderExist, renderEmpty, error, loading }) => {
if (!data) {
return <h1>Данных нет</h1>;
}
if (error) {
return <h1>При получении данных произошла ошибка</h1>;
}
if (loading) {
return <Spiner />;
}
return data && data.filter(Boolean).length > 0
? renderExist(data)
: renderEmpty()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment