Posts tagged with React

FBI WARNING: this may be an anti-pattern in regard to react's stateless design.

As is known to all, there're a lot of web components that can be mutated by user interactions, such as <input>, <select>, or the rich editor I am using now. These components are inconspicuous in daily development - we can easily modify the value by typing something in it or set the value property. However, as React comes with one-way data binding, these components seem to be out of control:

  1. A <Input> that maintains its own state of value can't be mutated from outside;
  2. A <Input> of which value is set via props can't update without outside control.

Finally, React put forward the concept of Controlled Components and Uncontrolled Components.