From 19cf7f914e3fea8aefe4c0fe1ba3a775d227e6f4 Mon Sep 17 00:00:00 2001 From: Alexander Erkhov Date: Wed, 21 Aug 2024 18:36:00 +0300 Subject: [PATCH] Clean up --- example/src/App.tsx | 30 +++++++++++++++--------------- src/index.tsx | 34 +++++++++++++++++----------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index 6204add..4c3eeb9 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -13,24 +13,24 @@ export default function App() { const baseName = defaultBasePrefix + '-' + defaultBasePostfix; useEffect(() => { - const loadBase = async (): Promise => { - setPath((await getDatabasePath(baseName)) || "can't find path"); - - // инициализирую подключение к базе - try { - await DB.open(baseName); - setOpened(true); - } catch (error: any) { - Alert.alert( - 'Внимание', - 'Не удалось открыть базу данных: ' + error.message - ); - } - }; - loadBase(); }, []); + const loadBase = async (): Promise => { + setPath((await getDatabasePath(baseName)) || "can't find path"); + + // инициализирую подключение к базе + try { + await DB.open(baseName); + setOpened(true); + } catch (error: any) { + Alert.alert( + 'Внимание', + 'Не удалось открыть базу данных: ' + error.message + ); + } + }; + return ( {opened ? ( diff --git a/src/index.tsx b/src/index.tsx index 6e3e048..ee8d3bf 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -17,22 +17,6 @@ const SQLiteExplorer = ({ params }: SQLiteExplorerProps) => { const [select, setSelect] = useState(''); useEffect(() => { - const loadBase = async () => { - try { - await DB.open(params); - setSignatures( - ((await DB.getTablesSignature()) || []).sort((a, b) => - a.name.localeCompare(b.name) - ) - ); - } catch (error: any) { - Alert.alert( - 'Внимание', - 'Не удалось открыть базу данных: ' + error.message - ); - } - }; - loadBase(); }, []); @@ -41,7 +25,23 @@ const SQLiteExplorer = ({ params }: SQLiteExplorerProps) => { signatures.find((signature) => signature.name === select) || null; if (!!curSignature) queryTableData(curSignature); - }, [select, signatures]); + }, [select]); + + const loadBase = async () => { + try { + await DB.open(params); + setSignatures( + ((await DB.getTablesSignature()) || []).sort((a, b) => + a.name.localeCompare(b.name) + ) + ); + } catch (error: any) { + Alert.alert( + 'Внимание', + 'Не удалось открыть базу данных: ' + error.message + ); + } + }; const queryTableData = async (signature: TableSignature) => { if (!signature) return;