fetchp icon indicating copy to clipboard operation
fetchp copied to clipboard

Update Readme for current usage

Open 9ssi7 opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe. Yes, it's about an issue. I was going to use fetchp for the first time today and I wanted to use it as reactive in a react project.

Describe the solution you'd like In the example there was a usage like:

import { useFetchp } from "fetchp";

const MyComponent = (props) => {
  const { data, isLoading, error } = useFetchp("GET", "/posts");

  if (isLoading) {
    return <div>Loading...</div>;
  }

  if (error) {
    return <div>Error: {error.message}</div>;
  }

  return <div>{JSON.stringify(data)}</div>;
};

But isLoading doesn't actually work as expected. isFetching meets the expectations of isLoading. So when I updated as below, the problem did not occur.

import { useFetchp } from "fetchp";

const MyComponent = (props) => {
  const { data, isFetching, error, doFetch } = useFetchp("GET", "/posts");

  useEffect(() => {
		  doFetch()
	  }, [])

  if (isFetching) {
    return <div>Loading...</div>;
  }

  if (error) {
    return <div>Error: {error.message}</div>;
  }

  return <div>{JSON.stringify(data)}</div>;
};

Also, no example is given for POST request. I was able to learn how to send parameters by examining the codes.

Describe alternatives you've considered

  • POST request usage example can be added.
  • Current usage should be added for React usage, it doesn't work when copying in Readme.

If we don't want the README to be long, we can at least prepare a documentation.

9ssi7 avatar Jan 22 '23 07:01 9ssi7