錯誤處理與除錯
在整合和使用 TacoTranslate 時,您可能會遇到一些問題。通常,這些問題都非常容易解決。以下是一些有助於調試的實用技巧:
檢查控制台日誌
當發生錯誤時,TacoTranslate 會輸出除錯資訊。
檢查網路請求
透過 tacotranslate
篩選請求並檢查其輸出。
TacoTranslate 透過 useTacoTranslate
鉤子提供一個錯誤物件,幫助你處理和偵錯錯誤。此物件包含翻譯過程中發生的任何錯誤資訊,讓你能在應用程式中適當回應。
import {useTacoTranslate, Translate} from 'tacotranslate/react';
function Page() {
const {error} = useTacoTranslate();
return (
<div>
{error ? <div>Error: {error.message}</div> : null}
<Translate string="Hello, world!" />
</div>
);
}