Q20 Observe the below code snippet. What will be the value of {counter.count} when the button is clicked 5 times const R
Posted: Fri May 20, 2022 9:58 am
Questions
Q20 Observe the below code snippet. What will be the value of {counter.count} when the button is clicked 5 times const RenderCounter = () => { const [age, setAge] = useState(0) const counter = useRef(0); const handleClick = () => { setAge(age + 1) } useEffect(0 => { counter.current = counter.current + 1; },0) return <div className="container"> <h1>{counter.current}</h1> <h1>{age}</h1> <button onClick={0 => handleClick()}>Click</button> </div> ); }; a) 0 b) 1 c) 5 d) Error as age is not passed as a dependency to useEffect method Q21 Consider an online application developed using React where the customer can buy Laptops. There is a new requirement where the buyer can customize their purchase by adding or removing the features. Each feature has a price associated. In order to add the above requirement to the application. Which of the following is the best option ? 11/14 a) useReducer Hook b) Custom Hook c) Hoc d) None of the above
React Js Q20 Observe the below code snippet. What will be the value of {counter.count} when the button is clicked 5 times const RenderCounter = () => { const [age, setAge] = useState(0) const counter = useRef(0); const handleClick = () => { setAge(age + 1) } useEffect(0 => { counter.current = counter.current + 1; },0) return <div className="container"> <h1>{counter.current}</h1> <h1>{age}</h1> <button onClick={0 => handleClick()}>Click</button> </div> ); }; a) 0 b) 1 c) 5 d) Error as age is not passed as a dependency to useEffect method Q21 Consider an online application developed using React where the customer can buy Laptops. There is a new requirement where the buyer can customize their purchase by adding or removing the features. Each feature has a price associated. In order to add the above requirement to the application. Which of the following is the best option ? 11/14 a) useReducer Hook b) Custom Hook c) Hoc d) None of the above