Last active
September 21, 2020 19:21
-
-
Save bogdanq/47b263d6a07d956de5487ecba210742a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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