Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

typehooks

Package Overview
Dependencies
4
Maintainers
1
Versions
2
Issues
File Explorer

Advanced tools

typehooks

TypeScript React Hooks Package

    1.0.12latest

Version published
Maintainers
1
Yearly downloads
219

Weekly downloads

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;
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc