showing results for - "react useeffect common dependency"
Leon
17 Jan 2017
1import React, { useState, useRef, useEffect } from "react";
2function EffectsDemoNoDependency() {
3  const [title, setTitle] = useState("default title");
4  const titleRef = useRef();
5  useEffect(() => {
6    console.log("useEffect");
7    document.title = title;
8  });
9  const handleClick = () => setTitle(titleRef.current.value);
10  console.log("render");
11  return (
12    <div>
13      <input ref={titleRef} />
14      <button onClick={handleClick}>change title</button>
15    </div>
16  );
17}