Socket
Socket
Sign inDemoInstall

typehooks

Package Overview
Dependencies
9
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    typehooks

TypeScript React Hooks Package


Version published
Maintainers
1
Created

Readme

Source

TypeHooks

TypeScript React Hooks Package

Installation

npm

  npm i typehooks

useLocalStorage

  • Includes Storage Event Listener, If Data Is Being Updated In One Window It Will Be Updated On All Other Windows
ParamTypeExample
namestringUsername
Example
import TypeHooks from  "typehooks";
import React from  "react";

interface  IProps  {}
type MyType = string;

const  Example:  React.FC<IProps>  =  ({})  =>  {
const { value,  setValue } = TypeHooks.useLocalStorage<MyType>("name");

     function update(){
      setValue('' as T) // inserted type, in my case string | MyType
    }

return  <div>
       {value}
  </div>;

};
export  default Example;

usePrevious

  • Will Keep The Previous & Current Value In A State
ParamTypeExample
value<T> / <undefined>MyValue
Example
import TypeHooks from  "typehooks";
import React from  "react";

interface  IProps  {}
type MyType = boolean;

const  Example:  React.FC<IProps>  =  ({})  =>  {
const  { setValue,  value, prev } = TypeHooks.usePrevious<MyType>(false)
      function update(){
        setValue('' as T) // Inserted Type, In This Case boolean | MyType
    }
return  <div>
       {prev} - {value}
  </div>;

};
export  default Example;

useToggle

  • Simple Boolean Toggle
ParamTypeExample
defaultVal<boolean> / <undefined>false
Example
import TypeHooks from "typehooks";
import React from "react";

interface IProps {}

const Example: React.FC<IProps> = ({}) => {
  const { toggle, value } = TypeHooks.useToggle(false);
  function update() {
    toggle(); // opposite of the current value
    toggle(false | true); // can take bool param too
  }
  return <div>{value}</div>;
};
export default Example;

FAQs

Last updated on 11 May 2022

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc