我正在使用react-testing-library和jest。在 componentdidupdate 中尝试获取“ this.testRef.current.offsetHeight ”,即使在加载内容后,offsetHeight 仍为0 。我想要 DOM 的精确 offsetHeight 因为有一些基于它的条件。
在反应测试库和笑话中是否有任何可能的解决方案可以解决。
我正在使用angerouslySetInnerHTML来绑定testRef 元素的html 内容。
我有一些多个状态和函数来使用 useState 钩子设置状态。
在每个 setstate 组件上重新渲染。我只想重新渲染完全完成的 setstate 功能。
例如:
在 app.js 中
const [a, setA] = useState(() => false);
const [b, setB] = useState(() => {});
const [c, setC] = useState(() => props.c);
const [d, setD] = useState(null);
const [e, setE] = useState(null);
const [f, setF] = useState(null);
const [g, setG] = useState('');
const func1 = useCallback(data => {
setA(true);
setB(true);
setC(data && data.c);
setD();
setE(isChecked ? 'a' : 'b');
}, []);
const func2 = useCallback(data => {
setA(false);
setB(false); …Run Code Online (Sandbox Code Playgroud)