0.1.3 • Published 5 months ago

@app-studio/react-request v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 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

8 months ago

0.0.86

8 months ago

0.0.87

8 months ago

0.0.88

8 months ago

0.0.89

8 months ago

0.0.80

8 months ago

0.0.81

8 months ago

0.0.82

8 months ago

0.0.74

8 months ago

0.0.75

8 months ago

0.0.76

8 months ago

0.0.77

8 months ago

0.0.78

8 months ago

0.0.79

8 months ago

0.1.0

8 months ago

0.1.2

5 months ago

0.1.1

7 months ago

0.1.3

5 months ago

0.0.95

8 months ago

0.0.96

8 months ago

0.0.97

8 months ago

0.0.98

8 months ago

0.0.99

8 months ago

0.0.90

8 months ago

0.0.91

8 months ago

0.0.92

8 months ago

0.0.93

8 months ago

0.0.94

8 months ago

0.0.72

1 year ago

0.0.63

1 year ago

0.0.66

1 year ago

0.0.67

1 year ago

0.0.68

1 year ago

0.0.69

1 year ago

0.0.60

1 year ago

0.0.59

1 year ago

0.0.58

1 year 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

3 years ago

0.0.22

3 years ago

0.0.23

3 years ago

0.0.12

3 years ago

0.0.24

3 years ago

0.0.13

3 years ago

0.0.25

3 years ago

0.0.14

3 years ago

0.0.26

3 years ago

0.0.15

3 years ago

0.0.16

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.19

3 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