From 1dc7c9ebb37d2736f48c9c4bb07963aa712d5d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Ko=C5=9Bcielniak?= Date: Wed, 24 Nov 2021 18:42:06 +0100 Subject: [PATCH] Add getTransactions query invalidation on successful addTransactino --- src/components/AddTransaction.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/AddTransaction.js b/src/components/AddTransaction.js index 522cd7a..44cb6cf 100644 --- a/src/components/AddTransaction.js +++ b/src/components/AddTransaction.js @@ -1,6 +1,6 @@ -import { useEffect, useState } from "react"; +import { useState } from "react"; import { TextInput, View, Text, Button, Picker } from "react-native-web"; -import { useMutation, useQuery } from "react-query"; +import { useMutation, useQuery, useQueryClient } from "react-query"; import { addTransaction } from "../queries/transactions"; import { getAccounts } from "../queries/accounts"; @@ -9,6 +9,8 @@ const AddTransaction = ({ budgetId }) => { const [valueText, setValueText] = useState(0); const [selectedAccountId, setSelectedAccountId] = useState(null); + const queryClient = useQueryClient(); + const { isLoading, data: responseData, @@ -37,12 +39,13 @@ const AddTransaction = ({ budgetId }) => { const { accounts } = responseData.data; const handleAddButton = () => { - console.log(selectedAccountId); mutation.mutate({ budgetId, payee: payeeText, value: valueText, accountId: selectedAccountId, + }, { + onSuccess: () => { queryClient.invalidateQueries(['transactions', budgetId])} }); };