我正在尝试使反应导航记住用户路径。
因此,将其保存在用户处于redux的位置。
当用户单击后退按钮,并以LIFO
方式弹出屏幕时。
我想知道我要尝试的方法是否正确。
问题是我的方式导致多次单击可触摸的东西。 如果多次单击,则与调用用户所在路径的堆栈有关的方法将多次调用,并在redux数组中多次堆叠路径。
这是我的代码。
clicked()
方法使clicked state
到true
。
init_clicked()
方法使clicked state
到false
。
mainScreen.js
/*
if click button then call moveToFavorite method.
*/
moveToFavorite = async () => {
const {fetching, ScreenActions, navigation, clicked} = this.props;
const {push, navigate} = navigation;
/*currunt state
{
userPath: [],
clicked: false
}
*/
if(!clicked) {
ScreenActions.clicked();
await ScreenActions.stackScreen('favorite'); // save the path name, 'favorite' to redux
/* state
{
userPath: ['favorite'],
clicked: false <= but what I expect was it should be 'true'
so it can make clicking multiple times.
if click twice then, userPath is ['favorite', 'favorite']
}
*/
navigate('FavoriteScreen');
}
}
favoriteScreen.js
componentDidMount() {
const {navigation, ScreenActions} = this.props;
ScreenActions.init_clicked(); // this one executes earlier than the ScreenActions.clicked() in favoriteScreen.js
//That's why state clicked state is changed to false right away.
}