typehooks
Advanced tools
TypeScript React Hooks Package
Weekly downloads
Readme
TypeScript React Hooks Package
npm
npm i typehooks
Param | Type | Example |
---|---|---|
name | string | Username |
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;
Param | Type | Example |
---|---|---|
value | <T> / <undefined> | MyValue |
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;
Param | Type | Example |
---|---|---|
defaultVal | <boolean> / <undefined> | false |
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;