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
.
Example
Single
Fetch on mount
; const PostList = <Fetchy url="https://jsonplaceholder.typicode.com/todos"> <div> <h1>Todos</h1> <button onClick=fetch>Refresh</button> <ul> todos || </ul> </div> </Fetchy>;
See CodeSandbox
Manual fetch
const PostList = <Fetchy> <button onClick= { ; }>Fetch me</button> </Fetchy>;
Options
See interface IFetchyRequestOptions
Multi
Fetch on mount
; const PostList = <FetchyMulti requests= id: "1" url: "https://jsonplaceholder.typicode.com/todos/1" id: "2" url: "https://jsonplaceholder.typicode.com/todos/2" id: "3" url: "https://jsonplaceholder.typicode.com/todos/3" > <pre>JSON</pre> </FetchyMulti>;
See CodeSandbox
Options
See interface IFetchyMultiOptions
License
MIT