Consider the code snippet below:
const App = () => {
return (
<div>
<Sum num1={5} num2={6} />
<Sum num1={4} num2={2} />
</div>
);
};
const Sum = () => {
return <p>[NUMBER 1] + [NUMBER 2]</p>;
};-
Consider the code above where we have our App functional component and a Sum functional component. What relationship would you say the App is to the Sum?
-
In the App we're passing different information into the Sum component. Why have we had to use {} brackets to send the numbers down -
num1={5}for example? -
From inside our Sum component, where do we have access to the
num1andnum2being passed in? -
When rendering a list of items, why can we only do a
mapand not aforEach? -
Why do we need to include
import React from 'react'at the top of each of our component files like App.js? -
Where would a 'Each React child needs a unique key' error come from and how could we solve it?
-
Make a user variable in the App that you display in the Header component: '[user here]'s Puppies'
-
Add a cuteness rating to the puppies and display that alongside their name
-
Extract the list of puppies into its own List component
-
Add a button next to the header that triggers a
console.logof 'Hello [user here]' when clicked. -
Add a list of kittens - bonus points if you reuse the list component (not making a separate 'KittenList' and 'PuppyList')
Consider the snippet below:
class App extends React.Component {
state = {
counter: 0
};
render() {
return (
<div>
<p>Count: {counter}</p>
<button onClick={this.incrementCount}>Increase counter</button>
</div>
);
}
incrementCount = () => {
// want to update the counter in state here
};
}-
Running the above code, we get an ReferenceError saying '
counteris not defined'. Why iscounternot defined? How should we refer to thecountervariable from inside the render? -
I want to increase the counter by 1 with every click of a button. If I try to update something in state directly like this:
this.state.counter++, I will mutate the state but won't see it update on the page. What do I need to do to properly update a value in state? -
What does
setStatetrigger? -
I want to take the value in state and increase it by one. Should I invoke
setStatewith an object or a function?
-
Add a 'sort by cuteness' button that re-orders the puppies
-
Add functionality to remove a puppy from the list
-
Add functionality to upvote a puppy's cuteness ranking
-
Give the puppies personalities (e.g
personalities: ['happy', 'excitable']in the pup object) and having a drop down/buttons etc that filters list to show puppies by personality -
let us know if you've got this far and we'll give some more fun tasks for you to do!