use-fetch-until-mounting
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

useFetchUntilMounting

Example

import { useFetchUntilMounting } from "use-fetch-until-mounting";
import { Suspense } from "react";

const App = () => {
  const fetch = useFetchUntilMounting([]);
  const [user, setUser] = useState(null);

  const fetchUser = () => fetch(async () => {
    const user = await loadUser();
    return () => {
      setUser(user)
    }
  })

  return (
    <div>
      <button onClick={fetchUser}>FETCH!</button>
      {user === null && <div>unknown</div>}
      {user !== null && <div>{user.displayName}</div>}
    </div>
  )
};

Installation

# npm
npm i use-fetch-until-mounting

# yarn
yarn add use-fetch-until-mounting

Dependencies (1)

Dev Dependencies (1)

Package Sidebar

Install

npm i use-fetch-until-mounting

Weekly Downloads

2

Version

1.0.9

License

MIT

Unpacked Size

3.75 kB

Total Files

5

Last publish

Collaborators

  • danuel