Last active
January 5, 2021 13:25
-
-
Save thatisuday/0076eeed1a08283ea18131db2d8a396e to your computer and use it in GitHub Desktop.
A sample React component with increment button.
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, { 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