DEV Community

Discussion on: How React’s useEffect Hook Changed My Life

Collapse
 
brense profile image
Rense Bakker • Edited

You can make it even better by using a ref!

function Content(){
  const contentRef = React.useRef();

  React.useEffect(()=>{
    contentRef.current.textContent = "New Text";
  }, []); 

  return (
    <p ref={contentRef}>Replace This Text</p>
  );
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
wbojczuk profile image
William Bojczuk

Great point!