Welcome everyone to guide and discuss:)
"Continuous Update" This article mainly records the author in the study of the problems encountered, and make a corresponding summary. Where there is a mistake, I hope you can support it.
I. getinitialstate in ES6 (Abstract: Constructor (props) and this.state)
/*ES6*/class ToDoList extends component{constructor (props) {super (props); This. State ={items: [' Hello ', ' World ', ' click ', ' Me ']}} render () {//.. } }/*CSS*/varToDoList =React.createclass ({getinitialstate:function() { return{items: [' Hello ', ' World ', ' click ', ' Me ']}; }, Render () {//... }})
Ii. setState in Es6 (Abstract: Fun.bind (this) and this.setstate)
/*ES6*/class ToDoList extends component{render () {return ( <div> <button onclick={ This. Handleadd.bind ( This)} >add item</button> </div>)} handleadd () {varNewItem = Prompt (' Enter a new ') varNewItems = [... This. State.items, NewItem]; This. SetState ({Items:newitems})}}
Summary and generalization of react problems