scrimba
React Hooks Tutorial: useRef
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

React Hooks Tutorial: useRef
AboutCommentsNotes
React Hooks Tutorial: useRef
Expand for more info
index.js
run
preview
console
import React, {useState, useEffect} from 'react';
import ReactDOM from 'react-dom';
import randomColor from 'randomcolor'

function Counter(props) {
const [count, setCount] = useState(0)
useEffect(() => {
// should run on mount
document.body.style.background = randomColor()
})
return (
<div>
<button onClick={() => setCount(state => state + 1)}>👍</button>
<h1>{count}</h1>
</div>
)
}

ReactDOM.render(<Counter />, document.getElementById('root'));
Console
index.html
-2:26