Sat Apr 05 2014
Paul Shan
var DisplayContainer1 = React.createClass({ updateValue:function(modifiedValue){ this.setState({ value:modifiedValue }) }, getInitialState:function(){ return{ value:'My Value' } }, render:function(){ return (In this case what we are doing is, once the value of the textbox in ‘InputBox1’ component is changed, we are calling a function of that component, named ‘update’. There we are storing the current value of the textbox in a variable named ‘modifiedValue’ and passing it as a parameter and calling the function updateValue() of the parent component ‘DisplayContainer1’, which was passed through ‘prop’. The ‘updateValue()’ function of ‘DisplayContainer1’ change the state variable ‘value’ and once it is changed, the modified value will be reflected everywhere as, ‘DisplayContainer1’ is the owner of the state ‘value’.); } }); var InputBox1 = React.createClass({ update:function(){ var modifiedValue=this.refs.inputValue.getDOMNode().value; this.props.updateValue(modifiedValue); }, render:function(){ return () } }); React.renderComponent({this.state.value}
,document.getElementById("container1"));
var DisplayContainer2 = React.createClass({ mixins: [React.addons.LinkedStateMixin], getInitialState:function(){ return{ value:'My Value' } }, render:function(){ return (Using ReactLinkMixin things are very easy. To use ReactLink you must include the react library react-with-addons.js to your html page. Once you include you are ready to use ReactLink. In this case, instead of sending a state variable as a property, you send a ReactLink. If you are using ReactLinkMixin, you can get a ReactLink of a state variable by using this.linkState(‘stateVarName’). This returns a ReactLink variable which has two properties inside it; ‘value’ and ‘requestChange()’. ‘value’ returns the value of the ReactLink and ‘requestChange()’ is fired automatically once your variable is changed. So by using ReactLink you don’t have to manually update anything in your parent or owner; it does all this from back automatically. Update: LinkedStateMixin is deprecated after react v15 and you need to use the package react-addons-linked-state-mixin); } }); var InputBox2 = React.createClass({ render:function(){ return () } }); React.renderComponent({this.state.value}
,document.getElementById("container2"));
var DisplayContainer3 = React.createClass({ update:function(modifiedValue){ this.setState({value: modifiedValue}); }, getInitialState:function(){ return{ value:'My Value' } }, render:function(){ var customValueLink={ value: this.state.value, requestChange: this.update }; return (Well, what reactLink does in back, we also can follow that approach without using the ReactLink mixing. We just have to create an object and name it whatever you want (as here I’ve given customValueLink). Inside that object make two variables, ‘value’ and ‘requestChange’ and assign them the state variable and a function which will update your state variable respectively. And that’s it; you now can use your custom ReactLink variable just like the original one. It will work just like ReactLinkMixin.); } }); var InputBox3 = React.createClass({ render:function(){ return () } }); React.renderComponent({this.state.value}
,document.getElementById("container3"));
SHARE THIS ARTICLE
Thu Mar 10 2016
OAuth authentications are pretty popular now a days and another thing which is popular is JavaScript. This article shows how to plugin google’s oAuth api for authentication in your own node application.Sat Mar 01 2014
This is a continuation of my CSS3 loader snippet collection series. I've provided spinning css3 animation loader in the part 1 of this series and here in part 2, I'm providing various square type loading