JSPM

@fracto/http-client

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q9304F
  • License MIT

Customizable React http client library

Package Exports

  • @fracto/http-client

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@fracto/http-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

http-client

Customizable React http client library

NPM JavaScript Style Guide

Install

npm install --save http-client

Usage

export default function App() {
    const [todos, setTodos] = useState([]);
    
    const todosAPI = useAPI("GET", "/todos");
    
    const fetchTodos = useCallback(() => {
        todosAPI.call();
    },  [todosAPI, params]);
    
    useEffect(() => {
        fetchTodos();
    }, []);
    
    useEffect(() => {
        if(todosAPI.networkState === 'success' && todosAPI.body) {
            setTodos(todosAPI.body);
        }
    }, [todosAPI.body, todosAPI.networkState]);
    
    return (
        <div>
            {todosAPI.loading && <div>Loading...</div>}
            {
                !todosAPI.loading && todosAPI.networkState === "success" && (
                    <div>
                        {todos.map((item) => (<div key={item.id}>{item.title}</div>))}
                    </div>
                )
            }
            {!todosAPI.loading && todosAPI.networkState === "error" && (<div>Error fetching todos</div>)}
        </div>
    );
}

See more advanced demo on codesandbox

License

MIT © https://github.com/fracto-team