scrimba
Learn React Hooks in one hour
useState & useEffect Challenge
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

useState & useEffect Challenge
AboutCommentsNotes
useState & useEffect Challenge
Expand for more info
app
components
Paint.js
run
preview
console
import React from 'react'
import Name from './Name'
import ColorPicker from './ColorPicker'
import randomColor from 'randomcolor'

export default function Paint() {
const getColors = () => {
const baseColor = randomColor().slice(1);
fetch(`https://www.thecolorapi.com/scheme?hex=${baseColor}&mode=monochrome`)
.then(res => res.json())
.then(res => {
setColors(res.colors.map(color => color.hex.value))
setActiveColor(res.colors[0].hex.value)
})
}
return (
<header style={{ borderTop: `10px solid ${activeColor}` }}>
<div className="app">
<Name />
</div>
<div style={{ marginTop: 10 }}>
<ColorPicker
colors={colors}
activeColor={activeColor}
setActiveColor={setActiveColor}
/>
</div>
</header>
)
}
Console
!
ReferenceError: activeColor is not defined (/app/components/Paint.js:40)
,
!
"The above error occurred in the <Paint> component: in Paint (created by App) in App Consider adding an error boundary to your tree to customize error handling behavior. Visit https://fb.me/react-error-boundaries to learn more about error boundaries."
,
ReferenceError: activeColor is not defined (/app/components/Paint.js:40)
,
index.html
-1:46