All Projects → sindresorhus → React Extras

sindresorhus / React Extras

Licence: mit
Useful components and utilities for working with React

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Extras

React Sticky El
Stars: ✭ 179 (-72.5%)
Mutual labels:  npm-package, react-component
Reactopt
A CLI React performance optimization tool that identifies potential unnecessary re-rendering
Stars: ✭ 1,975 (+203.38%)
Mutual labels:  npm-package, react-component
React Ckeditor
CKEditor component for React with plugin and custom event listeners support
Stars: ✭ 124 (-80.95%)
Mutual labels:  npm-package, react-component
React Router Util
Useful components and utilities for working with React Router
Stars: ✭ 320 (-50.84%)
Mutual labels:  npm-package, react-component
react-daterange-picker
A react date range picker to using @material-ui. Live Demo: https://flippingbitss.github.io/react-daterange-picker/
Stars: ✭ 85 (-86.94%)
Mutual labels:  react-component, npm-package
react-circle-flags
🚀 A React component with a collection of 300+ minimal circular SVG country flags. Wrapper of HatScripts/circle-flags
Stars: ✭ 29 (-95.55%)
Mutual labels:  react-component, npm-package
Create React Component Folder
Creates react component folder structure
Stars: ✭ 139 (-78.65%)
Mutual labels:  npm-package, react-component
react-windows-ui
Build Windows fluent UI apps using ReactJS. Provides a set of accessible, reusable, and composable React components that make it super easy to create websites and apps.
Stars: ✭ 383 (-41.17%)
Mutual labels:  react-component, npm-package
react-native-value-picker
Cross-Platform iOS(ish) style picker for react native.
Stars: ✭ 18 (-97.24%)
Mutual labels:  react-component, npm-package
React Pro Sidebar
Customizable and responsive react sidebar library with dropdown menus and unlimited number of nested submenus
Stars: ✭ 359 (-44.85%)
Mutual labels:  npm-package, react-component
Command Line Args
A mature, feature-complete library to parse command-line options.
Stars: ✭ 525 (-19.35%)
Mutual labels:  npm-package
Uiw
⚛️ @uiwjs A high quality UI Toolkit, A Component Library for React 16+.
Stars: ✭ 531 (-18.43%)
Mutual labels:  react-component
Pretty Ms
Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`
Stars: ✭ 599 (-7.99%)
Mutual labels:  npm-package
React Slider
Accessible, CSS agnostic, slider component for React.
Stars: ✭ 627 (-3.69%)
Mutual labels:  react-component
Normalize Url
Normalize a URL
Stars: ✭ 512 (-21.35%)
Mutual labels:  npm-package
React Text Loop
Animate words in your headings
Stars: ✭ 595 (-8.6%)
Mutual labels:  react-component
Synp
Convert yarn.lock to package-lock.json and vice versa
Stars: ✭ 510 (-21.66%)
Mutual labels:  npm-package
Input Moment
React datetime picker powered by momentjs
Stars: ✭ 507 (-22.12%)
Mutual labels:  react-component
React Event Timeline
A responsive event timeline in React.js
Stars: ✭ 504 (-22.58%)
Mutual labels:  react-component
Waud
Web Audio Library
Stars: ✭ 637 (-2.15%)
Mutual labels:  npm-package

react-extras

Useful components and utilities for working with React

Install

$ npm install react-extras

Usage

import React from 'react';
import {If} from 'react-extras';

const App = props => (
	<If condition={props.showUnicorn}>
		<div className="unicorn">
			🦄
		</div>
	</If>
);

API

autoBind(self, [options])

Automatically binds your React.Component subclass methods to the instance. See the autoBind.react() docs.

classNames(…input)

Conditionally join CSS class names together.

input

Type: string Object

Accepts a combination of strings and objects. Only object keys with truthy values are included. Anything else is ignored.

classNames('unicorn', 'rainbow');
//=> 'unicorn rainbow'

classNames({awesome: true, foo: false}, 'unicorn', {rainbow: false});
//=> 'awesome unicorn'

classNames('unicorn', null, undefined, 0, 1, {foo: null});
//=> 'unicorn'

const buttonType = 'main';
classNames({[`button-${buttonType}`]: true});
//=> 'button-main'
const Button = props => {
	console.log(props);
	/*
	{
		type: 'success',
		small: true
	}
	*/

	const buttonClass = classNames(
		'button',
		{
			[`button-${props.type}`]: props.type,
			'button-block': props.block,
			'button-small': props.small
		}
	);

	console.log(buttonClass);
	//=> 'button button-success button-small'

	return <button className={buttonClass}></button>;
};

<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:

<div>
	<If condition={props.error} render={() => (
		<h1>{props.error}</h1>
	)}/>
</div>

Or you could just use plain JavaScript:

<div>
	{props.error && (
		<h1>{props.error}</h1>
	)}
</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.

<div>
	<Choose>
		<Choose.When condition={props.success}>
			<h1>{props.success}</h1>
		</Choose.When>
		<Choose.When condition={props.error}>
			<h1>{props.error}</h1>
		</Choose.When>
		<Choose.Otherwise>
			<h1>😎</h1>
		</Choose.Otherwise>
	</Choose>
</div>

Or you could just use plain JavaScript:

<div>
	{(() => {
		if (props.success) {
			return <h1>{props.success}</h1>;
		}

		if (props.error) {
			return <h1>{props.error}</h1>;
		}

		return <h1>😎</h1>;
	})()}
</div>

<For/>

React component that iterates over the of prop and renders the render prop.

<div>
	<For of={['🌈', '🦄', '😎']} render={(item, index) =>
		<button key={index}>{item}</button>
	}/>
</div>

Or you could just use plain JavaScript:

<div>
	{['🌈', '🦄', '😎'].map((item, index) =>
		<button key={index}>{item}</button>
	)}
</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.

<Image
	url="https://sindresorhus.com/unicorn.jpg"
	fallbackUrl="https://sindresorhus.com/rainbow.jpg"
/>

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.

<If condition={props.isDarkMode}>
	<RootClass add="dark-mode"/>
</If>
<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:

.dark-mode body {
	background: #000;
}

.dark-mode a {
	
}

With <BodyClass/> you need to do:

body.dark-mode {
	background: #000;
}

.dark-mode a {
	
}

isStatelessComponent(Component)

Returns a boolean of whether the given Component is a functional stateless component.

getDisplayName(Component)

Returns the display name of the given Component.

canUseDOM

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.

Related

License

MIT © Sindre Sorhus

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].