2.0.7 • Published 11 months ago

react-favicon v2.0.7

Weekly downloads
18,260
License
MIT
Repository
github
Last release
11 months ago

react-favicon

Control the favicon from a React app

Version 2.x

The major version bump from 1.0.1 to 2.x versions does not include any API changes. The version bump was made because the build and release system was reworked from scratch, also the component was converted to use React's functional component API. Please report bugs if you encounter any.

Demo

https://oflisback.github.io/react-favicon

This example is available in example.

Installation

npm install react-favicon --save

Features

  • Update the favicon with a url or base64 encoded image
  • Animate through a list of urls
  • Toggle animation
  • Alert bubbles
  • Allow some favicons to be kept on the page, which may be desirable for desktop Safari
  • Custom icon overlay

Props

NameTypeDefaultRequiredDescription
alertCountnumber or stringnullNoNumber or string to display as icon overlay.
alertFillColorstringredNoAlert bubble background color.
alertTextColorstringwhiteNoAlert bubble text color.
iconSizenumber16NoSize of the favicon to avoid pixelization
animatedbooleantrueNoTrue to animate favicon (for supported icons)
animationDelaynumber500NoTime between animation frames
keepIconLinkfunction()() => falseNoReturn true to remove icon link from document head
renderOverlayfunction(canvas, context)nullNoFunction called to to draw custom favicon overlay
urlstring or array of stringsYesFavicon url or array of url:s to animate the icons

Usage

<Favicon url={[url1, url2, url3]} />

See example for the demo page source code. Basic usage is as simple as importing the react-favicon package and including a Favicon component in the react component tree.

import React from "react";
import ReactDOM from "react-dom";
import Favicon from "react-favicon";

ReactDOM.render(
  <div>
    <Favicon url="http://oflisback.github.io/react-favicon/img/github.ico" />
    <h1>Hello, Favicon!</h1>
  </div>,
  document.getElementById("root")
);