From 4182f1a6e3fefbb8f21b9d0bcf2d35fa1f1ad724 Mon Sep 17 00:00:00 2001 From: HF Date: Mon, 11 Jul 2022 18:01:01 +0200 Subject: [PATCH] fix some react errors --- src/components/Captcha.jsx | 2 +- src/components/embeds/TikTok.jsx | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/components/Captcha.jsx b/src/components/Captcha.jsx index 4f70c7ba..1b085dfc 100644 --- a/src/components/Captcha.jsx +++ b/src/components/Captcha.jsx @@ -54,7 +54,7 @@ const Captcha = ({ autoload, width }) => { setCaptchaData({ url: svgUrl, id: captchaid }); }; - useEffect(async () => { + useEffect(() => { if (autoload) { reloadCaptcha(); } diff --git a/src/components/embeds/TikTok.jsx b/src/components/embeds/TikTok.jsx index 3fc447c7..8cc87cfe 100644 --- a/src/components/embeds/TikTok.jsx +++ b/src/components/embeds/TikTok.jsx @@ -16,16 +16,19 @@ function getUserFromUrl(url) { const TikTok = ({ url }) => { const [embedCode, setEmbedCode] = useState(null); - useEffect(async () => { - const prot = window.location.protocol.startsWith('http') - ? window.location.protocol : 'https'; - // eslint-disable-next-line max-len - const tkurl = `${prot}//www.tiktok.com/oembed?url=${encodeURIComponent(url)}`; - const resp = await fetch(tkurl); - const embedData = await resp.json(); - if (embedData.html) { - setEmbedCode(embedData.html); + useEffect(() => { + async function fetchData() { + const prot = window.location.protocol.startsWith('http') + ? window.location.protocol : 'https'; + // eslint-disable-next-line max-len + const tkurl = `${prot}//www.tiktok.com/oembed?url=${encodeURIComponent(url)}`; + const resp = await fetch(tkurl); + const embedData = await resp.json(); + if (embedData.html) { + setEmbedCode(embedData.html); + } } + fetchData(); }, []); if (!embedCode) {