Skip to content

Instantly share code, notes, and snippets.

@jsmney
Last active April 20, 2020 16:48
Show Gist options
  • Save jsmney/2860e7e15b810fbec7db15f636d0e16b to your computer and use it in GitHub Desktop.
Save jsmney/2860e7e15b810fbec7db15f636d0e16b to your computer and use it in GitHub Desktop.
import React, {useState, useEffect} from 'react'
const BirdSanctuary = props => {
const [birds, setBirds] = useState([])
useEffect(()=>{
setBirds(props.getBirds())
},[])
const feedBird = birdId => {
// updates bird feed status locally and on our database
}
return (
<>
<h1>Welcome to the Jasmine Bird Sanctuary</h1>
{birds.map(bird => <SingleBird bird={bird} feedBird={feedBird} />}
</>
)
}
BirdSanctuary.defaultProps = {
getBirds: () => [
{id: 3, name: 'Polly', fed: false},
{id: 4, name: 'Tina', fed: true},
{id: 5, name: 'Marlow', fed: false}
]
}
export default BirdSanctuary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment