Skip to content

Commit

Permalink
refactor: move useEffect in useExtensions wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
sehnryr committed Nov 8, 2024
1 parent 8b40be5 commit d7de510
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 0 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ export default function App() {
const [extensions, setExtensions] = useState<Extension[]>([]);
const [repositoryUrl, setRepositoryUrl] = useState<string>("");

useEffect(() => {
getExtensions().then(setExtensions);
}, []);

return (
<ExtensionsContext.Provider
value={{
Expand Down
11 changes: 9 additions & 2 deletions src/context/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { createContext, useContext } from "react";
import { createContext, useContext, useEffect } from "react";

import { Extension } from "../types/extension.ts";
import { getExtensions } from "../services/tauri.service.ts";

export const ExtensionsContext = createContext<Extension[]>([]);

export function useExtensions(): {
extensions: Extension[];
setExtensions: (extensions: Extension[]) => void;
} {
return useContext(ExtensionsContext);
const { extensions, setExtensions } = useContext(ExtensionsContext);

useEffect(() => {
getExtensions().then(setExtensions);
}, []);

return { extensions, setExtensions };
}

0 comments on commit d7de510

Please sign in to comment.