React useState hook always comes as undefined when setting it in useEffect

In my React application, I have a useEffect that checks if an element has the display style none set to it. If it does then it should set the state to false, however it always comes back as undefined. const [testingProp, setTestingProp] = useState(); useEffect(() => { const styles = getComputedStyle(customerPropertyTypeSection.current); if (styles.display == ‘none’)… Read More React useState hook always comes as undefined when setting it in useEffect

useRef not allowing to access .current.clientHeight

I’m storing a reference to an image item using: const renderedImageRef = useRef(). The ref is then assigned in render() function using: <img ref={renderedImageRef} src=… /> In another JSX item below, I try to access renderedImageRef.current.clientHeight using: <div style={{top: `${renderedImageRef.current.clientHeight}px`}}>Hello world</div> but this produces an error in the console: Uncaught TypeError: Cannot read properties of… Read More useRef not allowing to access .current.clientHeight

How does React update ref?

import React, { useState, useEffect, useRef } from "react"; import ReactDOM from "react-dom"; import "./styles.css"; function App() { const [minus, setMinus] = useState(1); const ref = useRef(null); const handleClick = () => { setMinus(minus – 1); }; console.log("–>", ref.current, minus); useEffect(() => { console.log(`denp[minus]>`, ref.current); }, [minus]); return ( <div className="App"> {(minus >= 0 ||… Read More How does React update ref?

Typescript and useRef hook causing type error

I made a custom Checkbox component to handle events differently, code below: const DoubleClickCheckbox = ({ filter, handleDoubleClick, handleSingleClick }: DCCheckboxProps) => { const delay = 400; const timer = useRef(null); const classes = useStyles(); const flags = useFlags(); useEffect(() => { return () => { timer.current && clearTimeout(timer.current); }; }, []); // eslint-disable-next-line @typescript-eslint/ban-ts-comment… Read More Typescript and useRef hook causing type error