Answers for "react useeffect common dependency"

0

react useeffect common dependency

import React, { useState, useRef, useEffect } from "react";
function EffectsDemoNoDependency() {
  const [title, setTitle] = useState("default title");
  const titleRef = useRef();
  useEffect(() => {
    console.log("useEffect");
    document.title = title;
  });
  const handleClick = () => setTitle(titleRef.current.value);
  console.log("render");
  return (
    <div>
      <input ref={titleRef} />
      <button onClick={handleClick}>change title</button>
    </div>
  );
}
Posted by: Guest on June-25-2021

Code answers related to "react useeffect common dependency"

Code answers related to "Javascript"

Browse Popular Code Answers by Language