npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-zfetch

v1.3.0

Published

封装好的react-native网络请求库,基于rn-fetch-blob实现,可配置response拦截器以及适配器,可取消网络请求。

Downloads

30

Readme

react-native-zfetch

usage

yarn add react-native-zfetch or npm install --save react-native-zfetch

react-native link rn-fetch-blob

HeaderUtil

配置请求头header;

HeaderUtil.setHeaders({ 'Header-CompanyId':'', 'Header-CurTime':'', 'Header-UserId':'', 'Cookie':'token' });

serverDomain

配置服务器域名,每个server对应dev,test,uat,production域名环境;

Object.assign(serverDomain, AllEnv);

serverEnvironment

配置服务器环境;

serverEnvironment.currentEnvironment = 'test';

httpNetwork

发起网络请求;

httpNetwork.requestAction(actionUrl.loginAction('zan','123456')); //发起请求

cancelRequests

取消已发起的网络请求即,httpNetwork.cancelRequests(array);

注:cancelRequests参数传数组,如接口api/test/login,httpNetwork.cancelRequests(['login'])

Demo

1、初始化环境

App.js的componentWillMount中配置,为什么是componentWillMount,Component的生命周期componentWillMount->render->componentDidMout,组件是从子组件父组件由内往外执行渲染,所以在componentWillMount进行初始化配置,子组件componentDidMount中执行执行网络请求时网络相应配置已完成。

NetWork.js

import AllEnv from './AllEnv';
import {serverDomain, serverEnvironment, serverInterceptor} from '../netwokModule/dist/index';
import Environment from './Environment';
import interceptor from './serverInterceptor';

const Network = {

    initAppEnvironment: function () {
        serverEnvironment.currentEnvironment = Environment.currentEnvironment;
        Object.assign(serverDomain, AllEnv);
        Object.assign(serverInterceptor, interceptor);
    }
};

export default Network;


App.js 

import Network from './script/networkConfig/Network';

componentWillMount() {
    Network.initAppEnvironment();
}

2、拦截器与适配器

test:{
        interceptorResponse:function (json, action) {

            console.log('do something');

            return responseInterceptor.interceptResponse(json, action);
        },

        handlerResponseData:function (json) {

            return {};
        }
    }
    注意:test表示的是服务器名,多服务器时可以为每个服务器配置不同的拦截逻辑;


const responseInterceptor = {

    interceptResponse:function (json,action) {
        
        //处理自己的逻辑

        return { isIntercept:false, message:'成功了', error:{} };
    }
};

3、发起网络请求与取消网络请求

TestPage.js

import { httpNetwork } from 'react-native-zfetch';

componentDidMount() {
    httpNetwork.requestAction(actionUrl.loginAction('xxx','xxx',pageName), (data) => {

    }); //发起请求
}

componentWillUnmount() {
    httpNetwork.cancelRequests(['XXX']); //取消网络请求
}