我使用https://github.com/jacklam718/react-native-dialog-component作爲我的對話框,而且我在使用異步函數時沒有刷新對話框。我在例如使用它像使用react-native-dialog-component顯示它之前在對話框中強制刷新
render() {
return (
...
<Button onItemPressed={(item) => {
this.completeMovementDialog.show()
}}/>}
...
<CompleteMovementDialog onRefresh={() => this.getStationsNearToPlayer()}
ref={(completeMovementDialog) => {
this.completeMovementDialog = completeMovementDialog;
}}/>
的CompleteMovementDialog使用在componentDidMount()
的onRefresh方法,是一個DialogComponent
的包裝。當我刷新列表時,它工作正常,從後端檢索this.getStationsNearToPlayer()
。問題在於,CompleteMovementDialog
組件一旦被加載,組件就會被加載。所以當我打電話給this.startMovementDialog.show()
時,它不會再進入componentDidMount
,並且除非手動刷新,否則不會刷新列表。有沒有人有提示,我可以如何在show()
之前提前刷新清單?還是有更好的庫來顯示對話框?聽說ref
是不是一個好的做法...