官术网_书友最值得收藏!

  • MobX Quick Start Guide
  • Pavan Podila Michel Weststrate
  • 341字
  • 2021-08-05 10:34:20

The client state

The UI that you can see and manipulate on screen is the result of painting a visual representation of data. The shape of data hints at the kind of controls you provide for visualizing and manipulating this data. For example, if you have a list of items, you will likely show a List control that has an array of ListItems. Operations may include searching, paginating, filtering, sorting, or grouping the items in the list. The state of these operations is also captured as data and informs the visual representation.

The following diagram shows the direct relationship of an array with a List control:

In short, it is the data that takes on a pivotal role in describing the UI. Handling the structure and managing the changes that can happen to this data is what we commonly refer to as state management. State is just a synonym for the client-data that is rendered on the UI.

State management is the act of defining the shape of data and the operations that are used to manipulate it. In the context of the UI, it is called client-side state management.

As the complexity of the UI increases, more state is accumulated on the client. It gets to a point where state becomes the ultimate source of truth for whatever we see on the screen. This approach to UI development, where we elevate the importance of the client-state, has been one of the biggest shifts in the frontend world. There is an interesting equation that captures this relationship between UI and state:

fn is a transformation function that is applied on the state (the data) that produces a corresponding UI. In fact, a subtle meaning that is hidden here is that, given the same state, fn always produces the same UI.

In the context of React, the preceding equation can be written as follows:

The only difference here is that fn takes two inputs, props and state, which is the prescribed contract of a React component.

主站蜘蛛池模板: 永泰县| 朝阳区| 大方县| 馆陶县| 三台县| 宿州市| 华亭县| 威海市| 通榆县| 丹寨县| 郓城县| 湾仔区| 池州市| 双峰县| 巫溪县| 庆阳市| 红河县| 高雄市| 锡林郭勒盟| 桃源县| 岐山县| 汉中市| 南郑县| 红河县| 崇左市| 平武县| 郓城县| 建德市| 贺兰县| 册亨县| 贵港市| 吴川市| 乐陵市| 宁国市| 深水埗区| 武宣县| 阿拉善右旗| 红桥区| 航空| 武安市| 涟源市|