事件函数的三种绑定方式
can = () => { //this.can
console.log(“123”);
}
add(){//this.add.bind(this) ()=>this.add()
console.log(456);
}
setState的第二个参数
this.setState((
name : “silence”
),()=>{
console.log(this.state.name);
);
arguments转换成数组
Array.from(arguments).slice(0);
ref的三种写法
class Sum extends React.Component{
add = () => {
let a = this.refs.a.value;
let b = this.refs.b.value;
console.log(a,b);
this.refs.c.value = a + b;
}
render(){
const { time } = this.state;
return(
<>
+ <button onClick = {()=>this.add()}>=
</>
)
}
}
class Sum extends React.Component{
add = () => {
let a = this.a.value;
let b = this.b.value;
console.log(a,b);
this.c.value = a + b;
}
render(){
return(
<>
<input ref = {ele=>this.a = ele}/> + <input ref = {ele=>this.b = ele} /><button onClick = {()=>this.add()}>=
<input ref = {ele=>this.c = ele}/>
</>
)
}
}
class Sum extends React.Component{
constructor(props){
super(props);
this.a = React.createRef();
this.b = React.createRef();
this.c = React.createRef();
}
add = () => {
let a = this.a.current.value;
let b = this.b.current.value;
console.log(a,b);
this.c.current.value = a + b;
}
render(){
return(
<>
+ <button onClick = {()=>this.add()}>=
</>
)
}
}
React.forwardRef(); //???