1.1.12 • Published 3 years ago
@piximind/custom-hook v1.1.12
Installation
Using npm
$ npm i -g npm
$ npm i react react-dom @piximind/validation @piximind/custom-hookPre requirements:
$ npm i react version 18
$ npm i @piximind/validationuseEffectOnce:
code :
useEffectOnce(() => {
console.log("useEffectOnce");
})
this runs only once at the component build leveluseUpdateEffect:
code :
useUpdateEffect(() => {
console.log("useUpdateEffect");
},[DependencyList])
this launches after modifying dependencyuseWindowSize:
code :
const { width, height } = useWindowSize()
return screen sizeuseOnlineStatus:
code :
const onLineStatus = useOnlineStatus()
return network statususeEventListener:
code :
useEventListener("event" ,callbackFunction)
create event listeneruseClickOutside:
code :
useClickOutside(React.ref ,callbackFunction)
detect element clict out sideuseCustomState:
code :
const[state, setState]=useCustomState(value)useForm:
code :
const{state, onChange, onValidForm, isFormValid ,onReset}=useForm(isRealTimeValidation: true,data:IListElementUseForm)onReset function description : if you pass a false param into the onReset function the form will be setten to initial state, else the form will be totally emptied
Interfaces:
enum EListFunction {
isMail = "isMail",
hasUperCase = "hasUperCase",
hasLowerCase = "hasLowerCase",
hasNumber = "hasNumber",
isEmpty = "isEmpty",
isNumber = "isNumber",
isDate = "isDate",
isUrl = "isUrl",
isDateValidation = "isDateValidation",
hasAlpha = "hasAlpha",
hasSpecial = "hasSpecial",
hasSpecialDate = "hasSpecialDate",
checkIsDate = "checkIsDate",
isNotEmpty = "isNotEmpty",
isArray = "isArray",
isTrue = "isTrue",
}
interface IRule {
priority: number,
function: EListFunction,
messageError: string,
}
interface IListRules extends Array<IRule> { }
interface IElementUseForm {
value: string | number | boolean,
isRealTimeValidation?: boolean,
rules?: IListRules,
successMessage?: string,
key: string
}
interface IListElementUseForm extends Array<IElementUseForm> { }
interface IUseForm {
isRealTimeValidation?: boolean,
data: IListElementUseForm
}
interface IElementState {
value: string | number | boolean,
isValid: boolean,
successMessage: string,
isInvalid: boolean,
errorMessage: string,
}
interface IState {
[key: string]: IElementState;
}
interface IOnChnage {
value: string | number | boolean,
key: string
}
interface IUseFormResult {
state: IState,
onChange: Function,
onValidForm: Function,
isFormValid: boolean,
onReset: Function,
onUpdateData: Function,
onUpdateState: Function
}