react native 能不能在全局方法中处理 redux?

要怎么做才能在这个全局方法里修改 redux?

我想在 fetch 的时候处理 token 过期的情况,如下

fetch(url).then(response => {
    /**
    * 我想封装个请求方法,在这里处理 token 过期的情况,根据 response.status 来判断,
    * 然后触发修改 redux 的状态
    */
    if (reponse.ok) {
        return response.json();  // 数据解析方式
    }
    throw new Error('请求失败');
}).then(responseData => {
    ...
}).catch(error => console.log(error));
阅读 1.9k
1 个回答

export const store = createStore(rootReducer);
在别处引用就行了吧?!
store.dispatch({随便你想干啥})

推荐问题