Awesome Open Source
Awesome Open Source


Declarative fetch in React

npm version Build Status codecov


npm install -S holen

Basic Usage

// Fetch on mount
<Holen url="">
  {({data}) => <pre>{JSON.stringify(data, null, 2)}</pre>}

// Lazy fetch
<Holen lazy onResponse={handleResponse} url="">
  {({fetching, data, fetch, error}) => (
      <button onClick={fetch}>Load Data</button>
      <pre>{JSON.stringify(data, null, 2)}</pre>


body any

  body={JSON.stringify({ message: 'hello' })}
  {({data}) => <pre>{JSON.stringify(data, null, 2)}</pre>}

MDN - Body

children function

Children is a function that receives an object as its only argument.

The object contains the following keys:

  • fetching: bool
  • response: object
  • data: object
  • error: object
  • fetch: function
<Holen url="">
  {({data}) => <div>{}</div>}

credentials string

MDN - Credentials

headers string

MDN - Headers

lazy boolean

If true then the component will not perform the fetch on mount. You must use the fetch named argument in order to initiate the request.

<Holen lazy url="">
  {({fetching}) => {fetching && <div>Loading</div>}} // renders nothing, fetch was not started

method string - default GET

MDN - Method

onResponse function

callback called on the response.

const handleResponse = (error, response) => {
  if (error || !response.ok) {


  {({ data, fetch }) => (
      <button onClick={fetch}>Load Data</button>
      <pre>{JSON.stringify(data, null , 2)}</pre>

transformResponse function - default data => data

The transformResponse prop is a function that can be used to massage the response data. It receives one argument, data, and by default, performs an identity operation, returning the data passed to it.

type string - default json

The body method applied to the response. One of json, text, blob, arrayBuffer or formData.

url string

url of the request.

Alternatives To Holen
Select To Compare

Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Javascript (1,072,919
Reactjs (164,328
Fetch (8,867
Mdn (832
React Fetch (7