Created
February 7, 2023 13:44
-
-
Save wpflames/3f97b96eb5de4ebe919734c8347fda58 to your computer and use it in GitHub Desktop.
React - Spinner Component
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
import React, { Fragment } from 'react'; | |
import spinner from '../../assets/images/spinner.gif'; | |
const Spinner = () => ( | |
<Fragment> | |
<img | |
src={spinner} | |
alt='Loading...' | |
style={{ width: '200px', margin: 'auto', display: 'block' }} | |
/> | |
</Fragment> | |
); | |
export default Spinner; |
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
import React from 'react'; | |
import UserItem from './UserItem'; | |
import Spinner from '../layout/Spinner'; | |
import PropTypes from 'prop-types'; | |
const Users = ({ users, loading }) => { | |
if (loading) { | |
return <Spinner />; | |
} else { | |
return ( | |
<div style={userStyle}> | |
{users.map((user) => ( | |
<UserItem key={user.id} user={user} /> | |
))} | |
</div> | |
); | |
} | |
}; | |
Users.propTypes = { | |
users: PropTypes.array.isRequired, | |
loading: PropTypes.bool.isRequired, | |
}; | |
const userStyle = { | |
display: 'grid', | |
gridTemplateColumns: 'repeat(3, 1fr)', | |
gridGap: '1rem', | |
}; | |
export default Users; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment