🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@lsky/http-react

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lsky/http-react

Source
npmnpm
Version
0.0.2
Version published
Weekly downloads
10
42.86%
Maintainers
1
Weekly downloads
 
Created
Source

logo

Http React

A http React Component

✨ Features

  • Extends Axios
  • React Component
  • Support <HttpProvider />

📦 installing

npm

$ npm install @lsky/http-react --save

yarn

$ yarn add @lsky/http-react

And you need to install Axios and React

$ yarn add react axios

🔨 Example

import React from 'react'
import HttpReact, { Post, Get, HttpProvider } from '@lsky/http-react'

class Index extends React.Component {
  render() {
    return (
      <div>
        <HttpReact
          url="/test/test"
          data={{ param: 'abc' }}
          method="post"
          onResponse={(response) => { console.log('response: ', response) }}
          onError={(error) => console.log('error: ', error)}
          onLoading={(loading) => console.log('isLoading: ', loading)}
        >
          http react
        </HttpReact>
        <Post
          url="/test/test"
          data={{ param: 'abc' }}
          onResponse={(response) => { console.log('post: ', response) }}
        >
          post http react
        </Post>
        <Get
          url="/test/test"
          params={{ param: 'abc' }}
          onResponse={(response) => { console.log('get: ', response) }}
        >
          post http react
        </Get>

        <HttpProvider baseURL={"http://localhost:3000"}>
          <Post
            url="/test/test"
            data={{ path: '/test/test' }}
            onResponse={(response) => { console.log('post: ', response) }}
          >
            post http react
          </Post>
        </HttpProvider>
        <Get 
          url={get.url} 
          onResponse={(response) => { console.log('get: ', response) }} 
          loading={<div>loading...</div>} 
        />
      </div>
    )
  }
}

🍰 Components & PropTypes

HttpReact

attrtypedefault valuedesc
methodstringnullhttp method
urlstringnullurl
debouncenumber100debounce
datastring | plain object | URLSearchParamsnulldata is the data to be sent as the request body; Only applicable for request methods 'PUT', 'POST', and 'PATCH'
paramsplain objectnullparams are the URL parameters to be sent with the request
childrenReact.ReactChildnullreact node
loadingReact.ReactNode | booleannullshow in loading
onResponse(response) => voidnullonResponse
onError(error) => voidnullonError
onLoading(isLoading: boolean) => voidnullonLoading

Get

attrtypedefault valuedesc
urlstringnullurl
debouncenumber100debounce
paramsplain objectnullparams are the URL parameters to be sent with the request
childrenReact.ReactChildnullreact node
loadingReact.ReactNode | booleannullshow in loading
onResponse(response) => voidnullonResponse
onError(error) => voidnullonError
onLoading(isLoading: boolean) => voidnullonLoading

Post

attrtypedefault valuedesc
urlstringnullurl
debouncenumber100debounce
datastring | plain object | URLSearchParamsnulldata is the data to be sent as the request body; Only applicable for request methods 'PUT', 'POST', and 'PATCH'
paramsplain objectnullparams are the URL parameters to be sent with the request
childrenReact.ReactChildnullreact node
loadingReact.ReactNode | booleannullshow in loading
onResponse(response) => voidnullonResponse
onError(error) => voidnullonError
onLoading(isLoading: boolean) => voidnullonLoading

Keywords

react

FAQs

Package last updated on 30 Jul 2020

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