React componentWillUpdate
Posted ThisCall
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了React componentWillUpdate相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="js/react.js"></script>
<script src="js/react-dom.js"></script>
<script src="js/browser.min.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/babel">
var MySwitch = React.createClass({
componentWillUpdate:function(props,state){
console.log(state);
},
getInitialState:function(){
return {switch:false}
},
handleClick:function(){
this.setState({switch:!this.state.switch});
},
render:function(){
return <button onClick={this.handleClick}>
{"当前状态为:"+this.state.switch}
</button>
}
})
ReactDOM.render(
<MySwitch/>,
document.getElementById(‘example‘)
)
</script>
</body>
</html>
以上是关于React componentWillUpdate的主要内容,如果未能解决你的问题,请参考以下文章
import * as react from 'react' 与 import react from 'react' 有啥区别
“使用 JSX 时,React 必须在范围内”(react/react-in-jsx-scope 与 index.js 上的“window.React = React”)