Reactjs React native saga产量呼叫不起作用
我正在尝试使用redux saga编写一个api。我的servicesSaga.js是这样的Reactjs React native saga产量呼叫不起作用,reactjs,react-native,react-redux,redux-saga,saga,Reactjs,React Native,React Redux,Redux Saga,Saga,我正在尝试使用redux saga编写一个api。我的servicesSaga.js是这样的 import { FETCH_USER } from '../actions/actionTypes' import { delay } from 'redux-saga' import { call, put, takeEvery, takeLatest } from 'redux-saga/effects' import { _getUserInformation } from './api' c
import { FETCH_USER } from '../actions/actionTypes'
import { delay } from 'redux-saga'
import { call, put, takeEvery, takeLatest } from 'redux-saga/effects'
import { _getUserInformation } from './api'
const getUserInformation = function*(action) {
console.log("FONKSİYONA geldi")
console.log(action)
try {
console.log("try catche geldi")
const result = yield call(_getUserInformation, action)
console.log("result döndü")
if (result === true) {
yield put({ type: FETCH_USER })
}
} catch (error) {
}
}
export function* watchGetUserInformation() {
yield takeLatest(FETCH_USER, getUserInformation)
console.log("WatchUsere geldi")
}
我正试图从./api调用我的_getUserInformation方法,但yield调用方法不起作用。这是我的api.js
const url = 'http://myreduxproject.herokuapp.com/kayitGetir'
function* _getUserInformation(user) {
console.log("Apiye geldi" + user)
const response = yield fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: user.email,
})
})
console.log(response.data[0])
return yield (response.status === 201)
}
export const api ={
_getUserInformation
}
感谢您从现在起提供的帮助。生成器函数必须定义为function*yourFunction(){}请尝试以下更改 servicesSaga.js
function* getUserInformation(action) {
try {
const result = yield _getUserInformation(action) //pass user here
if (result) {
yield put({ type: FETCH_USER })
}
} catch (error) {
}
}
export function* watchGetUserInformation() {
yield takeLatest(FETCH_USER, getUserInformation)
}
api.js
const url = 'http://myreduxproject.herokuapp.com/kayitGetir'
function* _getUserInformation(user) {
const response = yield fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: user.email,
})
})
console.log('response',response);
return response;
}
export {
_getUserInformation
}
您是否正在运行reduxSaga()。在创建店铺后运行(YourSaga)?是的,console.log(“try Catch geldi”)正在运行。在调用“const result=yield call(_getUserInformation,action)”删除catch method时,非常欢迎您。请尝试了解有关生成器函数基础知识的更多信息,这对以后的工作很有帮助。您能为我推荐一个有关生成器函数基础知识的来源吗?