@hookers/use-data-loader
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

@hookers/use-data-loader

requires react 16.8+

Wait for a dom element to appear then execute a callback

install

yarn add @hookers/use-data-loader
import { useDataLoader } from '@hookers/use-data-loader';

export const Example: React.FC = () => {
    const dataLoader = async (searchTerm: string) => {
        const data = await ExternalApiCall(searchTerm);
        return proccessData(data);
    } 

    const [read, { error, currentData, isLoading }] = useDataLoader(dataLoader);
    
    return (
        <>
            <input type="text" placeholder="search..." onBlur={evt => read(evt.target.value)} />
            { isLoading ? <div>Loading</div> : null }
            { error ? <div>Error</div> : null }
            { data ? <div>{ data }</div> : null }
        </>
    );
}

Readme

Keywords

none

Package Sidebar

Install

npm i @hookers/use-data-loader

Weekly Downloads

43

Version

1.1.1

License

MIT

Unpacked Size

19.2 kB

Total Files

13

Last publish

Collaborators

  • tyson-skiba