Answers for "how to change favicon dynamic in react js"

0

how to change favicon dynamic in react js

import React from "react";

function getFaviconEl() {
  return document.getElementById("favicon");
}

function App() {

  const handleGoogle = () => {
    const favicon = getFaviconEl(); // Accessing favicon element
    favicon.href = "https://www.google.com/favicon.ico";  };

  const handleYoutube = () => {
    const favicon = getFaviconEl();
    favicon.href = " https://s.ytimg.com/yts/img/favicon-vfl8qSV2F.ico";  };

  return (
    <div className="App">
      <h1>Dynamically changing favicon</h1>
      <button onClick={handleGoogle}>Google</button>      <button onClick={handleYoutube}>YouTube</button>    </div>
  );
}

export default App;
Posted by: Guest on August-25-2021
0

reactjs change favicon

1. Open the react app in your favorite code editor.
2. Navigate to the public folder and delete the favicon.ico file.
3. Now, add a new favicon inside the public folder.
Posted by: Guest on July-27-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language