反应本机传奇 yield 调用不起作用

React native saga yield call is not working

我正在尝试使用 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'

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 yield 调用我的 _getUserInformation 方法,但 yield 调用方法不是 working.This 是我的 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
}