In this episode, we add a counter to show how many checkboxes are currently checked. We walk through creating a little UI section with flex styling to display the count, and discuss how this count should update both when you interact with checkboxes yourself and when other users do the same in real time.
We cover how the count value gets passed down as a prop from the controller, and why it's important that it stays updated—especially in collaborative scenarios. To keep things reactive, we use a ref for the count and make sure to increment or decrement it when any checkbox state changes, so it always reflects the correct number.
Finally, we show how this ties into our real-time updates so everyone sees the same count, even without refreshing. We also note a little limitation: ideally, we’d calculate the count based on the state of our checkboxes ref, but since we don’t have that in this setup, the workaround still gets the job done!