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

@chooks/use-axios

v1.0.0

Published

refetch가 발생할 때마다 API 요청을 처리해준다.

Downloads

10

Readme

Usage

refetch가 발생할 때마다 API 요청을 처리해준다.

import useAxios from "./useAxios";

const App = () => {
  const { loading, data, error, refetch } = useAxios({
    url: "https://yts.mx/api/v2/list_movies.json "
  });

  console.log(loading, refetch);

  return (
    <div>
      <h1>{data && data.status}</h1>
      <h2>{loading && "Loading"}</h2>
      <button onClick={refetch}>Refetch</button>
    </div>);
};

Logic

  1. useAxios를 호출하면서 API url을 인자로 보내준다.
  2. opts.url(API url)이 존재하면 useEffect가 호출되어 axiosInstance를 부른다. 이 때 인자로 opts를 보낸다.
  3. 성공하면 data를 setState하고 실패하면 error를 setState한다. 요청이 완료되어 loading 하지 않는 상태임으로 false로 세팅한다.
  4. refetch가 되면 loading을 true로 세팅하고 trigger를 Date.now()(겹치지 않는 숫자 발생)로 세팅한다. refetch로 인해 loading이 true로 변경된다.
  5. trigger가 변경되었으므로 다시 요청을 시도한다. 요청이 완료되었으니 loading은 false로, 성공 여부에 따라 data 또는 error가 세팅된다.