Transcript
00:00 we've got a bit of a problem in here. One of the bugs that we have is if I check dog and uncheck dog that works just fine and same with cat and check them both all that is working fine unless I go in here and type in dog and cat and those things are not checking and they kind of should
00:17 right because that like that's what it should look like when those things are in there and actually if I remove these then those don't get unchecked like it's super confusing for the user so we need to derive some state the the value of these checked boxes should be derived from the
00:34 value of the query and so we actually need to control these checked boxes based on what the current query is so that's interesting and we're going to be doing this with derived state so let's talk about derived state for a second here we've got a counter and we have a count and an
00:50 is even so anytime we handle the click of this button we're going to set the count and then also determine whether the new count is even this will function and it will work just fine but it's sub
01:04 optimal because what if we added another mechanism for updating the count and we forgot to call set is even on that then we'd get out of sync and that would not be good at all so it would be much
01:16 simpler if we can derive this state from this count right we we could do that and so it's actually pretty simple we only worry about updating the click and then we have is even
01:30 it's not state anymore we we got rid of that entirely and instead is even is derived it's calculated it's computed at the time our ui is being generated this might seem like a simple thing but a lot of developers fall into the trap of just saying oh this is some more state that i need to manage but not necessarily if you can derive it from existing state then you're in a
01:50 much better situation so that's what we're going to be doing for determining whether or not any of these checkboxes should be checked is based on the current state of the query we're going to derive those from the query so that's your job in this exercise i think you'll have a great time with it we'll see you when you're done