npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-silence

v1.0.4

Published

silence console errors

Readme

React Silence

A lightweight set of utils for silencing console output in a variety of contexts, including React components.

Getting started

npm install -D react-silence
import { silence, unsilence } from 'react-silence';

// Defaults to silencing errors
silence();
// Nothing will be logged
console.error('Annoying and unsuppressible message');
unsilence();

Utils

Most of the following utils follow a similar interface, taking spread arguments of one of two types:

  • logTypes - Available console methods: "error", "log", "warn", or "info".
  • matchers - Regular Expressions to match against. If they match console output of the specified logType, they will be blocked. If no matchers are provided, all logs of that output type will be blocked.

Note: If no log types are passed, "error" is provided as a default. If no matchers are passed, all logs of the specified type(s) are silenced by default.

By convention, log type args precede matcher args, but any order works.

silence

Simply turns off the console for the given types and any text matching the given matchers:

import { silence } from 'react-silence';

// Silence all errors - 'error' is default types argument
silence();
silence('error');

// Silence all warnings
silence('warn');

// Silence all warnings and errors
silence('warn', 'error');

// Silence all errors matching a regex
silence('error', /matches/);
console.error("This one matches and will be silenced");
console.error("This one doesn't and won't");

// Go crazy
silence('warn', 'error', 'info', /any/, /phrase/, /I/, /want/);

// Unsilence all console errors
unsilence('error')

// Or just unsilence everything
unsilence()

All calls to silence should be followed by a call to unsilence.

unsilence

Restores the log functions to their normal state. See above for examples.

silenceDescribe

In a Jest testing context, applies the silencing rules within a describe block, and unsilences when the tests are complete.

describe("some functionality", () => {
  silenceDescribe("errors", /matches/);
  //...
});

silenceWithin

The equivalent of sandwiching behavior between silence and unsilence calls:

silenceWithin(() => {
  console.warn("I'm silenced because I match.");
}, "warn", /match/);

console.warn("I'm not silenced, even though I match, because I'm outside the `silenceWithin` context.");

silenceFor

A convenience method for pre-applying the same logTypes and matchers to silence's methods:

const { silence, unsilence, /* etc */ } = silenceFor("warn", /match/);
silence();
console.warn("I'm silenced because I match.");
console.warn("I'm not because I don't.");
console.error("Although I match the regex, I'm not silenced, since I'm an error.");
unsilence();

useSilence

A React hook for silencing in a component context:

const QuietComponent = () => {
  useSilence("error", /SomeError/);

  return (
    <div>
      <MayLogSomeError />
      <p>Ahh... Silence.</p>
    </div>
  );
}

matchers

The library also exports a small matchers object defining a handful of regex matchers for convenience.