Gathering detailed insights and metrics for react-extras
Gathering detailed insights and metrics for react-extras
Gathering detailed insights and metrics for react-extras
Gathering detailed insights and metrics for react-extras
@times-components/article-extras
Extra information components at the bottom of the articles, such as topics, related articles and comments
react-jsonschema-rxnt-extras
RxNT Extra widgets for Mozilla's react-jsonschema-form
react-jsonschema-form-extras
Extra widgets for Mozilla's react-jsonschema-form
tamagui-extras
This repo is a mono-repo where `tamagui-extras` will be developed to add missing components and functionalities into the UI framework `tamagui`
npm install react-extras
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (81.79%)
TypeScript (18.21%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
722 Stars
57 Commits
39 Forks
10 Watchers
1 Branches
12 Contributors
Updated on Mar 19, 2025
Latest Version
3.0.1
Package Id
react-extras@3.0.1
Unpacked Size
22.71 kB
Size
6.52 kB
File Count
14
NPM Version
9.2.0
Node Version
16.20.0
Published on
Jun 07, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Useful components and utilities for working with React
1npm install react-extras
1import React from 'react'; 2import {If} from 'react-extras'; 3 4const App = props => ( 5 <If condition={props.showUnicorn}> 6 <div className="unicorn"> 7 🦄 8 </div> 9 </If> 10);
Automatically binds your React.Component
subclass methods to the instance. See the autoBind.react()
docs.
Conditionally join CSS class names together.
Type: string | object
Accepts a combination of strings and objects. Only object keys with truthy values are included. Anything else is ignored.
1import {classNames} from 'react-extras';
2
3classNames('unicorn', 'rainbow');
4//=> 'unicorn rainbow'
5
6classNames({awesome: true, foo: false}, 'unicorn', {rainbow: false});
7//=> 'awesome unicorn'
8
9classNames('unicorn', null, undefined, 0, 1, {foo: null});
10//=> 'unicorn'
11
12const buttonType = 'main';
13classNames({[`button-${buttonType}`]: true});
14//=> 'button-main'
1import {classNames} from 'react-extras'; 2 3const Button = props => { 4 console.log(props); 5 /* 6 { 7 type: 'success', 8 small: true 9 } 10 */ 11 12 const buttonClass = classNames( 13 'button', 14 { 15 [`button-${props.type}`]: props.type, 16 'button-block': props.block, 17 'button-small': props.small 18 } 19 ); 20 21 console.log(buttonClass); 22 //=> 'button button-success button-small' 23 24 return <button className={buttonClass}>…</button>; 25};
<If>
React component that renders the children if the condition
prop is true
.
Beware that even though the children are not rendered when the condition
is false
, they're still evaluated.
If you need it to not be evaluated on false
, you can pass a function to the render
prop that returns the children:
1import {If} from 'react-extras'; 2 3<div> 4 <If condition={props.error} render={() => ( 5 <h1>{props.error}</h1> 6 )}/> 7</div>
Or you could just use plain JavaScript:
1<div> 2 {props.error && ( 3 <h1>{props.error}</h1> 4 )} 5</div>
<Choose>
React component similar to a switch case. <Choose>
has 2 children components:
<Choose.When>
that renders the children if the condition
prop is true
.<Choose.Otherwise>
that renders the children if has no <Choose.When>
with true
prop condition
.Note that even when the children are not rendered, they're still evaluated.
1import {Choose} from 'react-extras'; 2 3<div> 4 <Choose> 5 <Choose.When condition={props.success}> 6 <h1>{props.success}</h1> 7 </Choose.When> 8 <Choose.When condition={props.error}> 9 <h1>{props.error}</h1> 10 </Choose.When> 11 <Choose.Otherwise> 12 <h1>😎</h1> 13 </Choose.Otherwise> 14 </Choose> 15</div>
Or you could just use plain JavaScript:
1<div> 2 {(() => { 3 if (props.success) { 4 return <h1>{props.success}</h1>; 5 } 6 7 if (props.error) { 8 return <h1>{props.error}</h1>; 9 } 10 11 return <h1>😎</h1>; 12 })()} 13</div>
<For/>
React component that iterates over the of
prop and renders the render
prop.
1import {For} from 'react-extras'; 2 3<div> 4 <For of={['🌈', '🦄', '😎']} render={(item, index) => 5 <button key={index}>{item}</button> 6 }/> 7</div>
Or you could just use plain JavaScript:
1<div> 2 {['🌈', '🦄', '😎'].map((item, index) => 3 <button key={index}>{item}</button> 4 )} 5</div>
<Image/>
React component that improves the <img>
element.
It makes the image invisible if it fails to load instead of showing the default broken image icon. Optionally, specify a fallback image URL.
1import {Image} from 'react-extras'; 2 3<Image 4 url="https://sindresorhus.com/unicorn.jpg" 5 fallbackUrl="https://sindresorhus.com/rainbow.jpg" 6/>
It supports all the props that <img>
supports, but you use the prop url
instead of src
.
<RootClass/>
Renderless React component that can add and remove classes to the root <html>
element. It accepts an add
prop for adding classes, and a remove
prop for removing classes. Both accept either a single class or multiple classes separated by space.
1import {RootClass} from 'react-extras'; 2 3<If condition={props.isDarkMode}> 4 <RootClass add="dark-mode"/> 5</If>
1import {RootClass} from 'react-extras'; 2 3<RootClass add="logged-in paid-user" remove="promo"/>
<BodyClass/>
Same as <RootClass/>
but for <body>
.
Prefer <RootClass/>
though, because it's nicer to put global classes on <html>
as you can consistently prefix everything with the class:
1.dark-mode body { 2 background: #000; 3} 4 5.dark-mode a { 6 … 7}
With <BodyClass/>
you need to do:
1body.dark-mode { 2 background: #000; 3} 4 5.dark-mode a { 6 … 7}
Returns a boolean of whether the given Component
is a functional stateless component.
Returns the display name of the given Component
.
A boolean of whether you're running in a context with a DOM. Can be used to check if your component is running in the browser or if it's being server-rendered.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 6/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More