UNPKG

1.39 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2013-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 */
8
9'use strict';
10
11/**
12 * ReactLink encapsulates a common pattern in which a component wants to modify
13 * a prop received from its parent. ReactLink allows the parent to pass down a
14 * value coupled with a callback that, when invoked, expresses an intent to
15 * modify that value. For example:
16 *
17 * React.createClass({
18 * getInitialState: function() {
19 * return {value: ''};
20 * },
21 * render: function() {
22 * var valueLink = new ReactLink(this.state.value, this._handleValueChange);
23 * return <input valueLink={valueLink} />;
24 * },
25 * _handleValueChange: function(newValue) {
26 * this.setState({value: newValue});
27 * }
28 * });
29 *
30 * We have provided some sugary mixins to make the creation and
31 * consumption of ReactLink easier; see LinkedValueUtils and LinkedStateMixin.
32 */
33
34/**
35 * Deprecated: An an easy way to express two-way binding with React.
36 * See https://facebook.github.io/react/docs/two-way-binding-helpers.html
37 *
38 * @param {*} value current value of the link
39 * @param {function} requestChange callback to request a change
40 */
41
42function ReactLink(value, requestChange) {
43 this.value = value;
44 this.requestChange = requestChange;
45}
46
47module.exports = ReactLink;
\No newline at end of file