项目作者: Ahmad-Saleem

项目描述 :
Custom React hooks for data fetching and mutation from mutiple data source (REST, Graphql)
高级语言: JavaScript
项目地址: git://github.com/Ahmad-Saleem/data-fetching.git
创建时间: 2020-02-28T09:29:31Z
项目社区:https://github.com/Ahmad-Saleem/data-fetching

开源协议:

下载


data-fetching

Hooks:

  • useFetch
  • useGet — comming soon —
  • usePost — comming soon —
  • usePut — comming soon —
  • useHead — comming soon —
  • useDelete — comming soon —
  • usePatch — comming soon —
  • useOptions — comming soon —

useFetch

  1. import React from 'react'
  2. import {RestProvider, useFetch} from 'data-fetching'
  3. export function View(){
  4. const {data, loading, error} = useFetch();
  5. if(loading) return <div>Loading...</div>
  6. if(!error && data) return (
  7. <div>
  8. {
  9. data.map((item,index) => <div key={index}>{item.title}</div>)
  10. }
  11. </div>
  12. )
  13. }
  14. function App() {
  15. return (
  16. <RestProvider value={{url: 'https://jsonplaceholder.typicode.com/posts'}}>
  17. <View ></View>
  18. </RestProvider>
  19. );
  20. }