小编Bùi*_*hôi的帖子

React-native fetch使javascript阻塞

每次我使用异步 等待着它的阻止了JS的线程和它的框架下降到1这里是我的代码:

export const apiCall = async (method, url, body) => {
    const token = await getLocalToken();
    const params = {
        method: method.toUpperCase(),
        headers: {
            Accept: 'application/json',
           'Content-Type': 'application/json'
        }
    };
    if (body) {
        params.body = JSON.stringify(body);
    }
    if (token) {
        params.headers.Authorization = `Bearer ${token}`;
    } 
    const start = Moment();
    const res = await fetch(`${apiUrl}${url}`, params);
    let json = res;     
    try {
        json = await res.json();
    } catch (e) {
        console.tron.log(e);
    }

    return json;
}
Run Code Online (Sandbox Code Playgroud)

javascript react-native redux-saga

5
推荐指数
0
解决办法
934
查看次数

标签 统计

javascript ×1

react-native ×1

redux-saga ×1