🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@acrool/react-fetcher

Package Overview
Dependencies
Maintainers
2
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@acrool/react-fetcher

Fetcher library based for Reactjs

latest
Source
npmnpm
Version
0.0.10
Version published
Maintainers
2
Created
Source

Acrool React Fetcher

Acrool React Fetcher is a solution for API integration and Auth state management in React projects. It helps you easily manage tokens, make API requests, perform GraphQL queries, and handle authentication flows.

Acrool React Fetcher Logo

A solution for API integration and token management in React projects

  • GraphQL
  • RestFul

NPM npm npm

npm downloads npm

Features

  • Token state management and custom refresh mechanism
  • GraphQL query support and custom fetcher
  • Seamless integration with Redux Toolkit Query
  • Flexible provider composition
  • Easy to test and simulate login/logout/token invalidation scenarios

Installation

yarn add @acrool/react-fetcher

Quick Start

1. Import styles

Add the following to your entry file (e.g. index.tsx):

import "@acrool/react-fetcher/dist/index.css";

2. Provider structure

Wrap your app with AuthStateProvider and AxiosClientProvider. It is recommended to use AppFetcherProvider to automatically wrap all necessary providers:

import AppFetcherProvider from '@/library/react-fetcher';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
  <AppFetcherProvider>
    <App />
  </AppFetcherProvider>
);

3. Create baseApi (GraphQL query)

For Redux Toolkit Query, create baseApi.ts:

import { createGraphQLFetcher } from '@acrool/react-fetcher';
import { createApi } from '@reduxjs/toolkit/query/react';
import { axiosInstance } from '@/library/react-fetcher';

export const baseApi = createApi({
  reducerPath: 'api',
  baseQuery: async (query, api, extraOptions) => {
    // Token handling and refresh are managed automatically
    const data = await createGraphQLFetcher(axiosInstance, query.document)(query.args);
    return { data };
  },
  endpoints: () => ({}),
});

4. Use Auth state and API in your pages

Get and update tokens

import { useAuthState } from '@acrool/react-fetcher';

const { getTokens, updateTokens } = useAuthState();

Send GraphQL query

const { data, refetch } = useGetBookmarkQuery({ variables: { bookmarkId: '1' } });

Simulate token invalidation and refresh

const handleMockTokenInvalid = () => {
  updateTokens(curr => ({
    ...curr,
    accessToken: 'mock-invalid-token',
  }));
  refetch();
};

Login/Logout

const login = useLogin();
const logout = useLogout();

await login({ variables: { input: { account, password } } });
logout();

5. More examples

  • The Dashboard page demonstrates how to operate token, API, and locale switching
  • The Login page demonstrates login and error handling

Options queryString

(.net not support) default: ?statusIds[]=1&statusIds[]=2

change to: ?statusIds=1&statusIds=2

export const baseQueryWithAxios: BaseQueryFn<IQuery> = async (query, BaseQueryApi, extraOptions) => {
    await mutex.waitForUnlock();
    try {
        const {url, method, fetchOptions, ...args} = query;
        const data = await createRestFulFetcher(axiosInstance, {url, method}, getContentTypeWithMethod)({
            ...args,
            fetchOptions: {
                ...fetchOptions,
                paramsSerializer: (params) => {
                    return qs.stringify(params, {indices: false});
                }
            }
        });

        return {
            data,
            meta: {}
        };

    } catch (error: any) {
        dialog.error(error.message, {code: error.code});

        return {
            error: {
                code: error.code || 500,
                message: error.message
            },
        };
    }
};

License

MIT Š Acrool & Imagine

Keywords

acrool

FAQs

Package last updated on 16 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts