UNPKG

reakit-warning

Version:

Reakit warning

75 lines (43 loc) 2.37 kB
# reakit-warning <a href="https://npmjs.org/package/reakit-warning"><img alt="NPM version" src="https://img.shields.io/npm/v/reakit-warning.svg?style=flat-square" /></a> > **This is experimental** and may have breaking changes in minor versions. ## Installation npm: ```sh npm i reakit-warning ``` Yarn: ```sh yarn add reakit-warning ``` ## Reducing bundle size Literal strings aren't minified. Keeping them in your production bundle may increase the bundle size significantly. To prevent that, you should: 1. Put `reakit-warning/babel-plugin` into your [babel config](https://babeljs.io/docs/en/plugins#plugin-options). This will make sure your `warning` and `useWarning` calls are wrapped within a condition that checks if `process.env.NODE_ENV !== 'production'`. 2. Use [UglifyJS](https://github.com/mishoo/UglifyJS2), [Terser](https://github.com/terser/terser) or any other JavaScript parser that performs [dead code elimination](https://en.wikipedia.org/wiki/Dead_code_elimination). This is usually used in conjunction with JavaScript bundlers, such as [webpack](https://github.com/webpack/webpack). When parsing the code in `production` mode, the `warning` call will be removed altogether. ## API <!-- Generated by documentation.js. Update this documentation by updating the source code. --> #### Table of Contents - [useWarning](#usewarning) - [warning](#warning) ### useWarning Logs `messages` to the console using `console.warn` based on a `condition`. This should be used inside components. #### Parameters - `condition` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** - `messages` **...[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;any>** ### warning Logs `messages` to the console using `console.warn` based on a `condition`. #### Parameters - `condition` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** - `messages` **...[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;any>** #### Examples ```javascript import { warning } from "reakit-warning"; warning(true, "a", "b"); // console.warn("a", "\n", "b") warning(false, "a", "b"); // does nothing ``` ## License MIT © [Diego Haz](https://github.com/diegohaz)