mirror of https://github.com/usememos/memos
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
698 B
TypeScript
36 lines
698 B
TypeScript
import { useState } from "react";
|
|
|
|
const useLoading = (initialState = true) => {
|
|
const [state, setState] = useState({ isLoading: initialState, isFailed: false, isSucceed: false });
|
|
|
|
return {
|
|
...state,
|
|
setLoading: () => {
|
|
setState({
|
|
...state,
|
|
isLoading: true,
|
|
isFailed: false,
|
|
isSucceed: false,
|
|
});
|
|
},
|
|
setFinish: () => {
|
|
setState({
|
|
...state,
|
|
isLoading: false,
|
|
isFailed: false,
|
|
isSucceed: true,
|
|
});
|
|
},
|
|
setError: () => {
|
|
setState({
|
|
...state,
|
|
isLoading: false,
|
|
isFailed: true,
|
|
isSucceed: false,
|
|
});
|
|
},
|
|
};
|
|
};
|
|
|
|
export default useLoading;
|