@pexip/hooks
TypeScript icon, indicating that this package has built-in type declarations

19.0.0 • Public • Published

@pexip/hooks

A common collection of reusable logic for react apps

Install

npm install @pexip/hooks

Usage

//Some Component
import React from 'react';

//import hooks from the package like this
import {usePromise} from '@pexip/hooks';

function broadcastResult = (res) => {
    console.log(res)
};

export const SomeComponent: React.FC<{}> = () => {
    const {error, loading, handleAction: handleSubmitButton} = usePromise(
        () => new Promise(resolve => {
            setTimeout(() => resolve('foo'), 2000);
        }),
        broadcastResult,
        error => {
            if (error) {
                throw error;
            }
        },
    );

    const ErrorMessage = error ? <p>{error}</p> : null;

    return (
        <Form onSubmit={handleSubmitButton}>
            <Button
                type="submit"
                disabled={loading}
            >
                {loading ? 'Loading...' : 'Continue'}
            </Button>
            <ErrorMessage/>
        </Form>
    )
};

Readme

Keywords

Package Sidebar

Install

npm i @pexip/hooks

Weekly Downloads

35

Version

19.0.0

License

Apache-2.0

Unpacked Size

44.1 kB

Total Files

38

Last publish

Collaborators

  • npm-pexip