Skip to content

Commit

Permalink
Create useAppwrite.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mayaif committed Jul 17, 2024
1 parent 5199556 commit 290fd9e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/useAppwrite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/** @format */
import { useState, useEffect } from "react";
import { Alert } from "react-native";
const useAppwrite = (fn) => {
const [data, setData] = useState([]);
const [isloading, setIsLoading] = useState(true);

const fetchData = async () => {
setIsLoading(true);
try {
const res = await fn();
setData(res);
} catch (error) {
Alert.alert("Error", error.message);
} finally {
setIsLoading(false);
}
};

useEffect(() => {
fetchData();
}, []);

const refetchData = () => fetchData();
return { data, isloading, refetchData };
};

export default useAppwrite;

0 comments on commit 290fd9e

Please sign in to comment.