基本上,我正在尝试实现一种解决方案,其中,每当用户每次从食谱书中更新食谱时,它都应将更新后的食谱发送到我的数据库中。但是,我注意到它“滞后”。例如,如果我更新配方,它将仅在调用fetch到我的后端时发布以前的更新。
我发现这是因为mapStateToProps在每次更新后最后一次被调用。但是,我需要在执行操作后立即调用它,这样,当我在后端调用fetch时,它将正确的信息发布到数据库中。我该怎么办?
type NotFinishedTBLFields struct {
Bulk_id int64
Recipient string
Operator string
Tracking_code string
}
func FetchNotFinishedTBLRows() *NotFinishedTBLFields {
rowValues := make(map[string]interface{})
var row NotFinishedTBLFields
iter := Instance().Query(fmt.Sprintf(`SELECT * FROM %q `, NotFinishedTBLConfig.Name)).Consistency(gocql.All).Iter()
for iter.MapScan(rowValues) {
fmt.Println("rowValues ",rowValues)
row = NotFinishedTBLFields{
Bulk_id: rowValues["bulk_id"].(int64),
Recipient: rowValues["recipient"].(string),
Operator: rowValues["operator"].(string),
Tracking_code: rowValues["tracking_code"].(string),
}
}
if err := iter.Close(); err != nil {
log.Fatal(err)
}
return &row
}
答案 0 :(得分:0)
事实证明,对异步函数updateBook()
的调用应该在名为componentDidUpdate()
的React.Component函数下,该函数在redux的connect函数之后被调用。