npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lsky/http-react

v0.0.4

Published

<p align="center"> <img src="./assets/orange.png" width="120" alt="logo" /> </p>

Downloads

1

Readme

✨ 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>
    )
  }
}

⚡️ WebSocket

import React from 'react'
import { WebSocket } from '@lsky/http-react'

const sendMsg = (socket) => {
  socket.send('message test')
}
const onMessage = (messageEvent) => {
  console.log('message: ', messageEvent)
}

class Index extends React.PureComponent {
  render() {
    return (
      <WebSocket
        url="ws://localhost:4000"
        onMessage={onMessage}
      >
        {({ socket }) => <div><button onClick={() => sendMsg(socket)}>send msg</button></div>}
      </WebSocket>
    )
  }
}

🍰 Components & PropTypes

HttpReact

| attr | type | default value | desc | | --- | --- | --- | --- | | method | string | null | http method | | url | string | null | url | | debounce | number | 500 | debounce | | data | string | plain object | URLSearchParams | null | data is the data to be sent as the request body; Only applicable for request methods 'PUT', 'POST', and 'PATCH' | | params | plain object | null | params are the URL parameters to be sent with the request | | children | React.ReactChild | null | react node | | loading | React.ReactNode | boolean | null | show in loading | | onResponse | (response) => void | null | onResponse | | onError | (error) => void | null | onError | | onLoading | (isLoading: boolean) => void | null | onLoading |

Get

| attr | type | default value | desc | | --- | --- | --- | --- | | url | string | null | url | | debounce | number | 500 | debounce | | params | plain object | null | params are the URL parameters to be sent with the request | | children | React.ReactChild | null | react node | | loading | React.ReactNode | boolean | null | show in loading | | onResponse | (response) => void | null | onResponse | | onError | (error) => void | null | onError | | onLoading | (isLoading: boolean) => void | null | onLoading |

Post

| attr | type | default value | desc | | --- | --- | --- | --- | | url | string | null | url | | debounce | number | 500 | debounce | | data | string | plain object | URLSearchParams | null | data is the data to be sent as the request body; Only applicable for request methods 'PUT', 'POST', and 'PATCH' | | params | plain object | null | params are the URL parameters to be sent with the request | | children | React.ReactChild | null | react node | | loading | React.ReactNode | boolean | null | show in loading | | onResponse | (response) => void | null | onResponse | | onError | (error) => void | null | onError | | onLoading | (isLoading: boolean) => void | null | onLoading |

WebSocket

| attr | type | default value | desc | | --- | --- | --- | --- | | url | string | null | websocket url | | timeout | number | 1000 | restart time | | max | number | 10 | restart count | | children | React.ReactNode | ({socket}) => React.ReactNode | null | react node | | onOpen | (event) => void | null | socket open callback | | onMessage | (messageEvent) => void | null | recieve message callback | | onClose | (closeEvent) => void | null | socket close callback | | onError | (event) => void | null | socket error callback |