Skip to content

Instantly share code, notes, and snippets.

@Dinir
Created May 15, 2016 06:18
Show Gist options
  • Save Dinir/e027baf7de14df47974f65c0a731ef80 to your computer and use it in GitHub Desktop.
Save Dinir/e027baf7de14df47974f65c0a731ef80 to your computer and use it in GitHub Desktop.
react.js take global variables
<body>
<div id="main"></div>
</body>
let stc = 37;
let stcc = (n=3) => {
stc += n;
console.log(stc);
}
let STT = React.createClass({
getInitialState: function() {
return {
stA: this.props.tn,
stB: this.props.ts,
stC: stc
}
},
getDefaultProps: function() {
return {
ts: "I am yet happy here.",
tn: 47
};
},
stcc: function(n) {
stcc(n);
this.setState({
stC: stc
});
},
render: function() {
return (
<div>
<span>{this.state.stC}</span>
<input type="button" onClick={()=>this.stcc(7)} value="!" />
</div>
)
}
});
ReactDOM.render(
<STT ts={"b"} tn={37} />,
document.getElementById("main")
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react-dom.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment