fenextjs-hook
Hook of Fenextjs
Documentation
https://fenextjs-hook-doc.vercel.app/
useData
Hook for handling Data Object
import { useData } from "fenextjs-hook/cjs/useData";
import { useData } from "fenextjs-hook/esm/useData";
interface ValueProps {
}
interface ValueMemoProps {
}
const {
data,
onChangeData,
isChange,
setData,
dataMemo,
setIsChange,
onRestart,
} = useData<
ValueProps,
ValueMemoProps
>(
defaultValue,
{
onChangeDataAfter: (data: ValueProps) => {
},
onMemo: (data: ValueProps) => {
const dataMemo : ValueMemoProps = {
}
return dataMemo
};
}
);
useRequest
Hook for request, loader and errors, with query and autoRequest
import { useRequest } from "fenextjs-hook/cjs/useRequest";
import { useRequest } from "fenextjs-hook/esm/useRequest";
interface QueryProps {
}
interface ResultProps {
}
interface ErrorProps {
}
type TypeProps = RequestResultTypeProps;
const {
result,
loader,
error,
onRequest,
} = useRequest<
QueryProps,
ResultProps,
ErrorProps,
TypeProps
>({
query,
request,
autoRequest,
});
useModal
Hook to save modal settings to localstorage using uselocalstoragenextjs
import { useModal } from "fenextjs-hook/cjs/useModal";
import { useModal } from "fenextjs-hook/esm/useModal";
interface useModalConfigContentProps {
key: string;
data: any;
}
interface useModalConfigProps {
active?: boolean;
use?: boolean;
loader?: boolean;
content?: useModalConfigContentProps[];
}
const {
valueModal,
loadModal,
updateModal,
setModal,
} = useModal();
useNotification
Hook to save notification settings to localstorage using uselocalstoragenextjs
import { useNotification } from "fenextjs-hook/cjs/useNotification";
import { useNotification } from "fenextjs-hook/esm/useNotification";
type NotificationType = "none" | "normal" | "ok" | "error" | "warning";
interface NotificationProps {
type?: NotificationType;
message: string;
}
const {
loadNotification,
notification,
pop,
reset,
} = useNotification({
time: 2000,
});
useQuery
Hook for handling Query Router
import { useQuery } from "fenextjs-hook/cjs/useQuery";
import { useQuery } from "fenextjs-hook/esm/useQuery";
const {
query,
setQuery,
onChangeQuery,
isChange,
} = useQuery();
useUser
Hook for handling User Auth
import { useUser } from "fenextjs-hook/cjs/useUser";
import { useUser } from "fenextjs-hook/esm/useUser";
const {
load,
user,
setUser,
onLogin,
onLogOut,
} = useUser({
validateTokenUser = async (user: UserProps) => {
if (!user.token) {
throw {
type: RequestResultTypeProps.ERROR,
message: "User not Token",
error: {
code: ErrorCode.USER_TOKEN_NOT_FOUNT,
message: "User not Token",
},
} as RequestResultDataProps;
}
try {
const token: UserProps = jwt_decode(user.token);
if (token?.id) {
return {
type: RequestResultTypeProps.OK,
message: "User Validate Ok",
} as RequestResultDataProps;
}
throw {
type: RequestResultTypeProps.ERROR,
message: "Token Invalid",
error: {
code: ErrorCode.USER_TOKEN_INVALID,
message: "Token Invalid",
},
} as RequestResultDataProps;
} catch (error) {
throw {
type: RequestResultTypeProps.ERROR,
message: "Token Invalid",
error: {
code: ErrorCode.USER_TOKEN_INVALID,
message: "Token Invalid",
},
} as RequestResultDataProps;
}
},
});
usePhone
Hook for handling Phone with code and number, useing world-phones
import { usePhone } from "fenextjs-hook/cjs/usePhone";
import { usePhone } from "fenextjs-hook/esm/usePhone";
const {
load,
codes,
phone,
setCode,
setNumber,
} = usePhone({
defaultValue: {
code: "",
number: "",
},
});
useCSC
Hook for handling Country/State/City, useing country-state-city-nextjs
import { useCSC } from "fenextjs-hook/cjs/useCSC";
import { useCSC } from "fenextjs-hook/esm/useCSC";
const {
load,
countrys,
states,
citys,
value,
onChangeCSC,
statesForCountrySelected,
citysForStateSelected,
} = useCSC({
defaultValue: {
country: {
id: 82,
text: "Colombia",
},
state: {
id: 1700,
id_country: 82,
text: "Antioquia",
},
city: {
id: 465167,
id_state: 1700,
text: "Medellín",
},
},
});
Developer
Francisco Blanco
Gitlab franciscoblancojn
Email blancofrancisco34@gmail.com
Repositories