react-lantern
v0.0.2
Published
Illuminate data management through delcarative react components. It doesn't include any fancy http clients or switching methods and instead relies soley on fetch (for now).
Downloads
3
Readme
react-lantern
Illuminate data management through delcarative react components. It doesn't include any fancy http clients or switching methods and instead relies soley on fetch (for now).
Installation
yarn add react-lantern
npm install --save react-lantern
Fetch polyfill and furture signal support
Depending on your use case you may need to polyfill fetch.
There is also a good chance that future releases of this library will rely on AbortController which has somewhat limited support. whatwg-fetch
does not polyfill for AbortController so another polyfill will be needed.
Usage
import React from 'react';
import { FetchProvider, Get } from 'react-lantern';
const FetchingAllDay = () => (
<FetchProvider baseUrl="https://jsonplaceholder.typicode.com">
<Get path="/posts">
{({ loading, error, data }) => {
if (loading) {
return <div>Loading...</div>;
}
if (error) {
return <div>Error...</div>;
}
return data.map((post: any) => <div key={post.id}>{post.title}</div>);
}}
</Get>
</FetchProvider>
);