Skip to content

Instantly share code, notes, and snippets.

@wpflames
Created February 7, 2023 11:56
Show Gist options
  • Save wpflames/2ac4eb7d093cc0063df2fd74ce99ac46 to your computer and use it in GitHub Desktop.
Save wpflames/2ac4eb7d093cc0063df2fd74ce99ac46 to your computer and use it in GitHub Desktop.
Stateless functional components
import React from 'react';
import PropTypes from 'prop-types';
const Navbar = ({ icon, title }) => {
return (
<nav className='navbar bg-primary'>
<h1>
<i className={icon} /> {title}
</h1>
</nav>
);
};
Navbar.defaultProps = {
title: 'GitHub Finder',
icon: 'fab fa-github',
};
Navbar.propTypes = {
title: PropTypes.string.isRequired,
icon: PropTypes.string.isRequired,
};
export default Navbar;
import React from 'react';
import PropTypes from 'prop-types';
const UserItem = ({ user: { login, avatar_url, html_url } }) => {
return (
<div className='card text-center'>
<img
className='round-img'
src={avatar_url}
alt={login}
style={{ width: '60px' }}
/>
<h3 className='card-title text-center'>{login}</h3>
<a className='btn btn-dark btn-sm my-1' href={html_url}>
More
</a>
</div>
);
};
UserItem.propTypes = {
user: PropTypes.object.isRequired,
};
export default UserItem;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment