Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/loicmahieu/react-fetchy


https://github.com/loicmahieu/react-fetchy

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# react-fetchy

[![Build Status](https://travis-ci.org/LoicMahieu/react-fetchy.svg?branch=master)](https://travis-ci.org/LoicMahieu/react-fetchy)
[![npm](https://img.shields.io/npm/v/react-fetchy.svg)](https://www.npmjs.com/package/react-fetchy)

react-fetchy is a React component that let makes fetch call easily by using "Function as Child components" pattern. Built on top of [`superagent`](http://visionmedia.github.io/superagent/).

### Example

#### Single

##### Fetch on mount

```js
import { Fetchy } from "react-fetchy";

const PostList = () => (

{({ fetch, state: { value: todos } }) => (


Todos


Refresh

    {(todos || []).map(todo =>
  • {todo.title}
  • )}


)}

);
```

See [CodeSandbox](https://codesandbox.io/s/pjrrk8nqrx)

##### Manual fetch

```js
const PostList = () => (

{({ fetch, state: { value: todos } }) => (
{
fetch({
url: "https://jsonplaceholder.typicode.com/todos",
});
}}>Fetch me
)}

);
```

##### Options

See [`interface IFetchyRequestOptions`](./src/Fetchy.tsx#L19-L30)

#### Multi

##### Fetch on mount

```js
import { FetchyMulti } from "react-fetchy";

const PostList = () => (

{({ states }) =>

{JSON.stringify(states, null, 2)}
}

);
```

See [CodeSandbox](https://codesandbox.io/s/n500mq8k1j)

##### Options

See [`interface IFetchyMultiOptions`](./src/FetchyMulti.tsx#L25-L28)

## License

MIT