UseEffect + Data Fetching
-
Question 1: What are the names of the tools you're using this week?
- Axios
- React!!!!
-
Question 2: Name some things about React
- State
- Components
- Children
- Props
- Hooks
- - JSX
- Stories - storybook
-
useEffect
- what kind of thing is this????
useEffect()
- similar to
useState()
, that's the pattern for a Hook- what's a hook? that's not today's quest
- Quick fact about Hooks: Hooks add functionality to components
Your Basic Component
const CoolComponent = ({ name }) => {
// LETS PUT SOME PIZAZZ IN HERE
return (
<h1>Ayy what up, { name }</h1>
)
}
// somewhere Else
<CoolComponent name="Bradlina">
<CoolComponent name="Josephetta-lynn>
- what does "effect" mean
-
you'll see the word "effect" in a couple different places
-
input -----> f() ------> output
-
f(x) = x + 2
-
every time you use the SAME input, you get the SAME output
-
input + state -----> f() -----> output
-
input ------> f() { network request } ------> output
-
- what does that even look like in react?
useEffect(() => {
console.log('HELLO')
}, [])
// in Express
app.get('/dogs', (req, res) => {
console.log('HELLO')
})
// in JQuery
$(document).ready(() => {
console.log('HELLO')
})
- why do we have to wrap that stuff up in useEffect?
- some neat demos
- maybe play around with inputs
- timers
- cleanup
- BREAK - go look up some cool APIs that we can play with!
- Data fetching with axios