This includes even the child components that weren’t affected by the change. By default, all child components re-render automatically when the state of a parent component changes. There is also another benefit of immutability. ![]() Avoiding direct data mutation lets you keep previous versions of the data intact, and reuse them later. This functionality isn’t specific to games-an ability to undo and redo certain actions is a common requirement for apps. Later in this tutorial, you will implement a “time travel” feature that lets you review the game’s history and “jump back” to past moves. Immutability makes complex features much easier to implement. The result is the same but by not mutating (changing the underlying data) directly, you gain several benefits. Now `squares` is unchanged, but `nextSquares` first element is 'X' rather than `null` In the end the user sees that the upper left square has changed from empty to having a X after clicking it. This causes the value prop of the Square component with index 0 to change from null to X. The squares state of the Board component was updated, so the Board and all of its children re-render.deleteCount: how many elements we need to remove from the array. ![]() start: In which index we need to start removing elements from the array.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |