CharlesMangwa / react-data-fetching

🎣 Declarative data fetching for React.
https://react-data-fetching.now.sh
MIT License
491 stars 27 forks source link

Enable to define different states #21

Open busypeoples opened 6 years ago

busypeoples commented 6 years ago

Opening up this issue for discussion, maybe this could be interesting. Enable to define different states and render them according to the current state. Check this out example using Tasks f.e. https://codesandbox.io/s/vv92zqqz0l

const App = () => (
   <Fetch
        url="https://api.github.com/users/octocat"
        timeout={5000}
        >
         {({ result }) => (
           {result.cata(
             {
               notAsked: () => <div>Nothing Loaded</div>,
               loading: () => <div>Loading...</div>,
               error: error => <div>Something went wrong: {error}</div>,
               success: ({ users }) => (
                 <ul>{users.map(user => <UserComponent key={user.id} {...user} />)}</ul>
               )
            })
        )}
   </Fetch>
);
CharlesMangwa commented 6 years ago

Hi @busypeoples! Just saw your PR #22, so let's gather all the discussing there and close this issue when everything will be implemented :)