showing results for - "how to change favicon dynamic in react js"
Maël
04 May 2020
1import React from "react";
2
3function getFaviconEl() {
4  return document.getElementById("favicon");
5}
6
7function App() {
8
9  const handleGoogle = () => {
10    const favicon = getFaviconEl(); // Accessing favicon element
11    favicon.href = "https://www.google.com/favicon.ico";  };
12
13  const handleYoutube = () => {
14    const favicon = getFaviconEl();
15    favicon.href = " https://s.ytimg.com/yts/img/favicon-vfl8qSV2F.ico";  };
16
17  return (
18    <div className="App">
19      <h1>Dynamically changing favicon</h1>
20      <button onClick={handleGoogle}>Google</button>      <button onClick={handleYoutube}>YouTube</button>    </div>
21  );
22}
23
24export default App;