React Day 3 Flashcards
10:22 - (conditional) ternary operator = handy for …
simple things/one line pieces of code/if-else statements
email.read ? ‘email read’ : email
if email.read is true then display email read, if false, display only just the email
its onchange, onclick, onsubmit, as it is ppointing out the type of button.
ie addeventlistener (“click”)
checked={false}
checked={true}
checked={email
no checked boxes
all checked boxes
read - checked boxes
problem: We need to change the checked attribute
solution:
I need to update ‘email.read’ via state
[roblem: When we click the checkbox we should see a chnag ine email.
solution:
I need to update ‘email.read’ via state
you can still carry functions liek function toggleREad ()
But, there’s another way:
const toggleRead = ()
What do we have that we can use to update state?
setword/setEmails
a function is declared
and it is called next to onChange (which is another way of adding an event Listener ) , we then need to pass through an email, so we need to find an object that represents an email. So onchange ={() => toggleRead(email)
Whenever checkbox is clicked, it will display that email on concsole.log
… So now we have the target email in there
email.map is not a function
we are setting emails with an object when emails is meant to be an array (of emails)
If this eerror appears, make sure you are putting the correct data type in
.map, .forEach, etc. all of these ……… have …………. running through them
.map, .forEach, etc. all of these array methods have for loops running through them