0.1.3 • Published 8 months ago

@app-studio/react-request v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

React Request

npm version npm License: MIT styled with prettier

✨ Features

  • 🎣 React Hooks - Modern React hooks API for data fetching
  • 🚀 TypeScript Support - Full TypeScript support with type safety
  • 💾 Built-in Caching - Automatic request caching with configurable TTL
  • 🔄 Loading States - Automatic loading and progress tracking
  • Error Handling - Comprehensive error handling with retry logic
  • 📝 Form Integration - Seamless Formik integration for forms
  • 🌐 Network Awareness - Online/offline status handling
  • 🔧 Configurable - Highly customizable with global and per-request options
  • 🎯 Debouncing - Built-in request debouncing (300ms)
  • 📊 Progress Tracking - Upload/download progress monitoring

📦 Install

npm install @app-studio/react-request

🔨 Usage

Basic Example

import React from 'react';
import { useRequest, request } from '@app-studio/react-request';

// Define your API function
const fetchUser = (id) =>
  request({
    url: `https://api.example.com/users/${id}`,
    method: 'GET'
  });

// Use in component
function UserProfile({ userId }) {
  const { data, loading, error, run } = useRequest(fetchUser);

  React.useEffect(() => {
    run(userId);
  }, [userId]);

  if (loading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;
  if (!data) return null;

  return (
    <div>
      <h1>{data.name}</h1>
      <p>{data.email}</p>
    </div>
  );
}

With Provider (Recommended)

import React from 'react';
import { RequestProvider } from '@app-studio/react-request';

function App() {
  return (
    <RequestProvider
      cached={true}
      debug={true}
      defaults={{
        onError: (error) => console.error('Request failed:', error),
        onSuccess: (data) => console.log('Request succeeded:', data)
      }}
    >
      <UserProfile userId="123" />
    </RequestProvider>
  );
}

Form Integration

import { Formik, Form, Field } from 'formik';

function CreateUserForm() {
  const { formikConfig, loading, error } = useRequest(
    (userData) => request({
      url: '/api/users',
      method: 'POST',
      params: userData
    }),
    {
      method: 'POST',
      onSuccess: (data) => alert('User created successfully!')
    }
  );

  return (
    <Formik initialValues={{ name: '', email: '' }} {...formikConfig}>
      <Form>
        <Field name="name" placeholder="Name" />
        <Field name="email" placeholder="Email" />
        <button type="submit" disabled={loading}>
          {loading ? 'Creating...' : 'Create User'}
        </button>
        {error && <div>Error: {error.message}</div>}
      </Form>
    </Formik>
  );
}

TypeScript

react-request is written in TypeScript with complete definitions.

📚 Documentation

🔗 Links

🤝 Contributing PRs Welcome

We welcome all contributions! Here's how you can help:

  1. 🐛 Report bugs - Create an issue
  2. 💡 Suggest features - Start a discussion
  3. 📝 Improve docs - Help us make the documentation better
  4. 🔧 Submit PRs - Fix bugs or add new features

Development Setup

git clone https://github.com/rize-network/react-request.git
cd react-request
npm install
npm start

Running Tests

npm test

Please read our contributing guide for more details.

Let's fund issues in this repository

❤️ Sponsors and Backers npm.io npm.io

npm.io

npm.io

Author

SteedMonteiro, steed@rize.network

License

React Request is available under the MIT license. See the LICENSE file for more info.

0.0.85

12 months ago

0.0.86

12 months ago

0.0.87

12 months ago

0.0.88

12 months ago

0.0.89

12 months ago

0.0.80

12 months ago

0.0.81

12 months ago

0.0.82

12 months ago

0.0.74

12 months ago

0.0.75

12 months ago

0.0.76

12 months ago

0.0.77

12 months ago

0.0.78

12 months ago

0.0.79

12 months ago

0.1.0

11 months ago

0.1.2

9 months ago

0.1.1

10 months ago

0.1.3

8 months ago

0.0.95

11 months ago

0.0.96

11 months ago

0.0.97

11 months ago

0.0.98

11 months ago

0.0.99

11 months ago

0.0.90

12 months ago

0.0.91

12 months ago

0.0.92

12 months ago

0.0.93

12 months ago

0.0.94

12 months ago

0.0.72

2 years ago

0.0.63

2 years ago

0.0.66

2 years ago

0.0.67

2 years ago

0.0.68

2 years ago

0.0.69

2 years ago

0.0.60

2 years ago

0.0.59

2 years ago

0.0.58

2 years ago

0.0.47

2 years ago

0.0.51

2 years ago

0.0.52

2 years ago

0.0.53

2 years ago

0.0.54

2 years ago

0.0.55

2 years ago

0.0.56

2 years ago

0.0.57

2 years ago

0.0.50

2 years ago

0.0.48

2 years ago

0.0.49

2 years ago

0.0.42

2 years ago

0.0.43

2 years ago

0.0.44

2 years ago

0.0.45

2 years ago

0.0.46

2 years ago

0.0.39

3 years ago

0.0.37

3 years ago

0.0.38

3 years ago

0.0.36

3 years ago

0.0.30

3 years ago

0.0.31

3 years ago

0.0.32

3 years ago

0.0.33

3 years ago

0.0.34

3 years ago

0.0.35

3 years ago

0.0.27

3 years ago

0.0.28

3 years ago

0.0.29

3 years ago

0.0.20

4 years ago

0.0.22

4 years ago

0.0.23

4 years ago

0.0.12

4 years ago

0.0.24

4 years ago

0.0.13

4 years ago

0.0.25

4 years ago

0.0.14

4 years ago

0.0.26

4 years ago

0.0.15

4 years ago

0.0.16

4 years ago

0.0.17

4 years ago

0.0.18

4 years ago

0.0.19

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.2

4 years ago