Skip to content

Instantly share code, notes, and snippets.

@thatisuday
Last active January 5, 2021 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thatisuday/0076eeed1a08283ea18131db2d8a396e to your computer and use it in GitHub Desktop.
Save thatisuday/0076eeed1a08283ea18131db2d8a396e to your computer and use it in GitHub Desktop.
A sample React component with increment button.
import React, { useState } from 'react';
// local dependencies
import { getVersion } from 'common/util';
// import styles (for compilation)
import './styles.scss';
// export a react component
export default ( props ) => {
const [ count, incrementCount ] = useState( 0 );
return (
<div className='hello'>
<h1>Hello { props.name } World!</h1>
<h3>Version: { getVersion() }</h3>
<h3>Counter: { count }</h3>
<button
onClick={ () => incrementCount( count + 1 ) }
className={ count % 2 === 1 ? 'hello__btn--odd' : undefined }
>Increment Counter</button>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment