Reactjs 函数无法正常工作
Reactjs function is not working as it is supposed to be
我有这个函数发生器
function* importWall(action) {
const { mnemonic, password, num_addresses, address, navigation } = action;
const network = yield select(getSelectedNetwork);
const importedWallet = yield call(
importAccount,
mnemonic,
password,
num_addresses,
network.name
);
const newAccount = {
name: 'Account 1',
password: action.password,
nonce: 0,
id: 0,
address: importedWallet,
mnemonic: action.mnemonic,
};
yield put(setUser(newAccount));
yield addWallet({
...newAccount,
active: true,
});
yield put(getWalletBalance(newAccount, network));
if (address === undefined) {
yield takeLatest(actionTypes.IMPORT_WALLET, importWall);
console.log('w');
} else {
navigation.navigate('Main');
}
}
除了我的条件语句外,一切正常,我尝试了几种方法,但如果地址未定义,我将无法再次调用此生成器。请就如何实现它提出任何建议?
你的 takeLatest 不应在效果处理程序中 'importWall'
function* runSagas () {
yield takeLatest(actionTypes.IMPORT_WALLET, importWall);
}
Take latest 是一个 fork 效果,它启动类型 'IMPORT_WALLET' 的操作通道
并将 运行 importWall 来处理这些操作。您不需要从效果处理程序中重新(获取最新)。
如果你需要的是重试机制。然后简单地重新启动原来的动作。
if (address === undefined) {
yield put(action);
}
我有这个函数发生器
function* importWall(action) {
const { mnemonic, password, num_addresses, address, navigation } = action;
const network = yield select(getSelectedNetwork);
const importedWallet = yield call(
importAccount,
mnemonic,
password,
num_addresses,
network.name
);
const newAccount = {
name: 'Account 1',
password: action.password,
nonce: 0,
id: 0,
address: importedWallet,
mnemonic: action.mnemonic,
};
yield put(setUser(newAccount));
yield addWallet({
...newAccount,
active: true,
});
yield put(getWalletBalance(newAccount, network));
if (address === undefined) {
yield takeLatest(actionTypes.IMPORT_WALLET, importWall);
console.log('w');
} else {
navigation.navigate('Main');
}
}
除了我的条件语句外,一切正常,我尝试了几种方法,但如果地址未定义,我将无法再次调用此生成器。请就如何实现它提出任何建议?
你的 takeLatest 不应在效果处理程序中 'importWall'
function* runSagas () {
yield takeLatest(actionTypes.IMPORT_WALLET, importWall);
}
Take latest 是一个 fork 效果,它启动类型 'IMPORT_WALLET' 的操作通道 并将 运行 importWall 来处理这些操作。您不需要从效果处理程序中重新(获取最新)。
如果你需要的是重试机制。然后简单地重新启动原来的动作。
if (address === undefined) {
yield put(action);
}