Socket
Book a DemoInstallSign in
Socket

@aquelle1/line-and-sinker

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aquelle1/line-and-sinker

Hooks used on my various projects

0.0.8
latest
npmnpm
Version published
Maintainers
1
Created
Source
import {
    useArray, useFetch, usePromise
} from "@aquelle1/line-and-sinker"

import {
    useOnes, useZeroes
} from "@aquelle1/line-and-sinker/lib/useArray"

Usages:

const [actions, value] = useArray([]);      // state-aware array
const [actions, value] = useOnes(N);        // state-aware single-row multi-dimension array filled with ones
const [actions, value] = useZeroes(N);      // state-aware single-row multi-dimension array filled with zeroes
const [actions, value] = useOnes(N, n);     // state-aware multi-dimension array filled with ones
const [actions, value] = useZeroes(N, n);   // state-aware multi-dimension array filled with zeroes
/*
    actions: {function} = {
      setValue,     // set the internal array
      unshift,
      push,
      clear,
      removeIndex,
      pop,
      shift
    };
    value: array // internal array
*/
const promise = useFetch("route", {             // state-aware fetch query
    fetch: "opts"
})
const promise = usePromise(new Promise(...))    // state-aware promise
/*
    promise = {
        request: function,  // helper to re-evaluate the promise
        data: json | text,  // data received from promise
        isLoading: bool,    // promise still in progress
        error: Error        // promise error was handled
    }
*/

Examples:

import React, {
    useEffect
} from "react"
import {
    useArray, useFetch
} from "@aquelle1/line-and-sinker"

export default () => {
    const {
        data, isLoading, error
    } = useFetch("https://api.myjson.com/bins/yg6te")

    const [{
        setValue: updateArrayValue
    }, arrayValue] = useArray([])

    useEffect(() => {
        if(!isLoading)
            updateArrayValue(data)
    }, [isLoading])

    return (
        <>
            Array value is: {arrayValue}
        </>
    )
}

Keywords

react

FAQs

Package last updated on 05 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.