No description, website, or topics provided.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src Implement option `withCredentials` Sep 14, 2018
test Implement option `withCredentials` Sep 14, 2018
.gitignore test Sep 13, 2018
.travis.yml travis Sep 14, 2018
LICENSE.md license Sep 14, 2018
README.md README: update Sep 14, 2018
package.json 1.0.3 Sep 14, 2018
tsconfig.json stable ? Sep 13, 2018
tslint.json Simplify lint Sep 14, 2018
yarn.lock more tests Sep 13, 2018

README.md

react-fetchy

Build Status npm

react-fetchy is a React component that let makes fetch call easily by using "Function as Child components" pattern. Built on top of superagent.

Example

Fetch on mount

const PostList = () => (
  <Fetchy url="https://jsonplaceholder.typicode.com/todos">
    {({ fetch, state: { value: todos } }) => (
      <div>
        <h1>Todos</h1>
        <button onClick={fetch}>Refresh</button>
        <ul>
          {(todos || []).map(todo => <li key={todo.id}>{todo.title}</li>)}
        </ul>
      </div>
    )}
  </Fetchy>
);

See CodeSandbox

Manual fetch

const PostList = () => (
  <Fetchy>
    {({ fetch, state: { value: todos } }) => (
      <button onClick={e => {
        fetch({
          url: "https://jsonplaceholder.typicode.com/todos",
        });
      }}>Fetch me</button>
    )}
  </Fetchy>
);

Options

See interface IOptions

License

MIT