Skip to content

Commit

Permalink
Avoid re rendering the quote when translating to Spanish
Browse files Browse the repository at this point in the history
fix/translate-quote
  • Loading branch information
danifromecuador committed Dec 6, 2024
1 parent c5f49a3 commit a73b0b8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/doing/Doing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,22 @@ 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) }
}
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 (
<div className='Doing'>
<h1>{text.doing.title}</h1>
Expand Down

0 comments on commit a73b0b8

Please sign in to comment.