我一直收到此错误,我一直尝试不显示任何图像,直到图像加载完毕,但是我得到了React Limits渲染次数以防止无限循环。如果您知道更好的方法,请告诉我。我希望图像在加载时非常丑陋,并且不显示...正在加载图像,并且仅在使用.Png文件的Mobile Im上发生。我应该转换为svg,以便加载速度更快吗?
Too many re-renders. React limits the number of renders to prevent an infinite loop.
▶ 2 stack frames were collapsed.
Spinner
C:/Users/Test/Documents/GitHub/Ecommerce-Store/src/components/Spinner.jsx:26
23 | return (
24 | <div style={{ height: '100vh' }}>
25 | <img
> 26 | onLoad={setloaded('true')}
| ^ 27 | id="preloader"
28 | src={preloader}
29 | alt="loading..."
import React, { useEffect, useState } from 'react';
import { isAndroid, isIOS } from 'react-device-detect';
import android from '../spinners/androidlogo.png';
import apple from '../spinners/Applelogo.png';
import spinner from '../spinners/VHUBLogospin.gif';
const Spinner = props => {
const [preloader, setpreloader] = useState(null);
const [loaded, setloaded] = useState(false)
// const productConsumer = useContext(ProductContext);
// // const { showSpinner } = productConsumer;
useEffect(() => {
if (isIOS) {
setpreloader(apple);
} else if (isAndroid) {
setpreloader(android);
} else {
setpreloader(spinner);
}
// showSpinner(preloader);
}, []);
return (
<div style={{ height: '100vh' }}>
<img
onLoad={setloaded('true')}
id="preloader"
src={preloader}
alt="loading..."
style={{
width: '200px',
margin: 'auto',
display: 'block',
marginTop: '3%',
paddingTop: '25vh',
}}
className={!loaded ? 'display-none' : '' }
/>
</div>
);
};
export default Spinner;
答案 0 :(得分:1)
尝试一下await page.waitForSelector("yt-formatted-string.count-text.style-scope.ytd-comments-header-renderer")
let commentCount = await (await (await page.$("yt-formatted-string.count-text.style-scope.ytd-comments-header-renderer")).getProperty("textContent")).jsonValue()