UNPKG

1.07 kBJavaScriptView Raw
1/**
2 * Copyright 2013-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
8 *
9 */
10
11'use strict';
12
13var ReactLink = require('./ReactLink');
14var ReactStateSetters = require('./ReactStateSetters');
15
16/**
17 * A simple mixin around ReactLink.forState().
18 * See https://facebook.github.io/react/docs/two-way-binding-helpers.html
19 */
20var LinkedStateMixin = {
21 /**
22 * Create a ReactLink that's linked to part of this component's state. The
23 * ReactLink will have the current value of this.state[key] and will call
24 * setState() when a change is requested.
25 *
26 * @param {string} key state key to update.
27 * @return {ReactLink} ReactLink instance linking to the state.
28 */
29 linkState: function (key) {
30 return new ReactLink(this.state[key], ReactStateSetters.createStateKeySetter(this, key));
31 }
32};
33
34module.exports = LinkedStateMixin;
\No newline at end of file