0.2.0-beta.14 • Published 6 years ago

@refetty/fetch v0.2.0-beta.14

Weekly downloads
95
License
MIT
Repository
github
Last release
6 years ago

Fetch

Basic usage

Install: yarn add @refetty/fetch

Create a fetch.js:

import { stateProvider } from '@refetty/fetch'
import axios from 'axios'

const request = axios.create({
  baseURL: 'https://jsonplaceholder.typicode.com',
});

const handler = options => state =>
  request({
    ...options,
		headers: {
			...options.headers,
    	...(state.token && { Authorization: `Bearer ${state.token}` }
    }
  })

const initialState = {}

export const fetch = stateProvider(hanlder, initialState)

And to change instance state:

fetch.setState(prev => ({ ...prev, token: '123' }))

Advanced Usage

0.2.0-beta.14

6 years ago

0.2.0-beta.13

6 years ago

0.2.0-beta.12

6 years ago

0.2.0-beta.10

6 years ago

0.2.0-beta.9

6 years ago

0.2.0-beta.8

6 years ago

0.2.0-beta.7

6 years ago

0.2.0-beta.6

6 years ago

0.2.0-beta.3

6 years ago