用于在函数组件 useState 中创建回调
For to create callback in function component useState
在class组件中我们可以
this.setState({
fieldValue: fieldVal,
fieldDirection: FieldDirection,
sort: Sort
}, ()=>{
callback()
});
this.setState({
fieldValue: fieldVal,
fieldDirection: FieldDirection,
sort: Sort,
addition: additional
}, ()=>{
callback1()
});
在函数组件中我们如何useEffect
调用不同的函数
const method1 = () => {
setFieldValue(val.value)
setFieldDirection(val.direction)
setFieldSort(val.sort)
callback() // field value is not update then callback is executed
}
const method2 = () => {
setFieldValue(val.value)
setFieldDirection(val.direction)
setFieldSort(val.sort)
setAddition(val.addition)
callback1() // field value/direction.sort/additional is not update then callback is executed
}
使用useEffect和状态组合解决
在class组件中我们可以
this.setState({
fieldValue: fieldVal,
fieldDirection: FieldDirection,
sort: Sort
}, ()=>{
callback()
});
this.setState({
fieldValue: fieldVal,
fieldDirection: FieldDirection,
sort: Sort,
addition: additional
}, ()=>{
callback1()
});
在函数组件中我们如何useEffect
调用不同的函数
const method1 = () => {
setFieldValue(val.value)
setFieldDirection(val.direction)
setFieldSort(val.sort)
callback() // field value is not update then callback is executed
}
const method2 = () => {
setFieldValue(val.value)
setFieldDirection(val.direction)
setFieldSort(val.sort)
setAddition(val.addition)
callback1() // field value/direction.sort/additional is not update then callback is executed
}
使用useEffect和状态组合解决