From a73b0b826bae5872f47cd4d2abf663346f309472 Mon Sep 17 00:00:00 2001 From: dani Date: Thu, 5 Dec 2024 22:04:28 -0500 Subject: [PATCH] Avoid re rendering the quote when translating to Spanish fix/translate-quote --- src/doing/Doing.jsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/doing/Doing.jsx b/src/doing/Doing.jsx index a272d46..4628b9f 100644 --- a/src/doing/Doing.jsx +++ b/src/doing/Doing.jsx @@ -64,11 +64,6 @@ export const Doing = () => { } }) setQuote(response.data.content.slice(0, -1)) // Delete the last dot of the quote - // translate quote to spanish - if (store.language.current === "spanish") { - let quoteTranslated = await axios(`https://api.mymemory.translated.net/get?q=${quote}&langpair=en|es`) - setQuote(quoteTranslated.data.responseData.translatedText) - } setAuthor(response.data.author) } catch (error) { console.error("Error fetching the quote: ", error.message) } @@ -76,6 +71,15 @@ export const Doing = () => { fetchQuote() }, [fetchNewQuote]) + const translateQuote = async () => { + let quoteTranslated = await axios(`https://api.mymemory.translated.net/get?q=${quote}&langpair=en|es`) + setQuote(quoteTranslated.data.responseData.translatedText) + } + + useEffect(() => { + if (store.language.current === "spanish") translateQuote() + }, [author]) + return (

{text.doing.title}