【发布时间】:2018-12-23 19:06:43
【问题描述】:
我在我的 React Native 应用程序中使用 redux saga。除了一件事,这一切都有效。对于我第一次分派时的一个操作,它在下面的代码中停在“const newUserLogAction = yield take('CREATE_USER_LOG')”处。所以控制台日志 'saga callCreateUserLog take' 没有打印出来,什么也没有发生。但是,如果我再次发送相同的操作,它就会起作用。我还有其他动作,它们第一次都可以正常工作。
传奇文件:
function * createUserLog () {
yield takeEvery('CREATE_USER_LOG', callCreateUserLog)
}
export function * callCreateUserLog () {
try {
console.log('saga callCreateUserLog start')
const newUserLogAction = yield take('CREATE_USER_LOG')
console.log('saga callCreateUserLog take')
console.log('newUserLogAction' + FJSON.plain(newUserLogAction))
const data = newUserLogAction.data
const newUserLog = yield call(api.createUserLog, data)
yield put({type: 'CREATE_USER_LOG_SUCCEEDED', newUserLog: newUserLog})
} catch (error) {
yield put({type: 'CREATE_USER_LOG_FAILED', error})
}
}
动作文件:
export const createUserLog = (data) => {
console.log('action create user log data = ' + FJSON.plain(data))
return ({
type: 'CREATE_USER_LOG',
data}
)
}
即使在第一次调度时,这里的数据也是正确打印的,因此有效负载是正确的。
react 本地函数进行调度:
clickContinue = () => {
var event = {
'userId': this.props.user.id,
'eventDetails': {
'event': 'Agreed to the ISA Declaration'
}
}
this.props.dispatch(createUserLog(event))
}
【问题讨论】:
标签: react-native redux redux-saga