Skip to content

Instantly share code, notes, and snippets.

@wpflames
Created February 7, 2023 13:44
Show Gist options
  • Save wpflames/3f97b96eb5de4ebe919734c8347fda58 to your computer and use it in GitHub Desktop.
Save wpflames/3f97b96eb5de4ebe919734c8347fda58 to your computer and use it in GitHub Desktop.
React - Spinner Component
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;
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