1.0.9 • Published 3 years ago

use-fetch-until-mounting v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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
1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago