Skip to content

Instantly share code, notes, and snippets.

@inPhoenix
Last active December 29, 2018 11:41
Show Gist options
  • Save inPhoenix/6ebbfcc7fd471a4afbd09e9bee1f5589 to your computer and use it in GitHub Desktop.
Save inPhoenix/6ebbfcc7fd471a4afbd09e9bee1f5589 to your computer and use it in GitHub Desktop.
React Hook Simple Example
// https://daveceddia.com/intro-to-hooks/
import React, { useState } from 'react';
import { render } from 'react-dom';
function OneTimeButton(props) {
const [clicked, setClicked] = useState(true) // setClicked update the clicked state.
function clickedTest() {
props.onClick()
setClicked(!clicked)
console.log('%c clicked', 'color: #243b79 ', clicked);
}
return (
<button onClick={clickedTest}>
You Can Only Click Me Once
</button>
);
}
function sayHi() {
console.log('hi');
}
render(
<OneTimeButton onClick={sayHi}/>,
document.querySelector('#root')
);
// Install using: yarn add react@next react-dom@next
// Package.json Dependencies:
// "dependencies": {
// "react": "^16.7.0-alpha.0",
// "react-dom": "^16.7.0-alpha.0",
// "react-scripts": "2.0.4"
// },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment