0.20.0 • Published 2 years ago
bang-button v0.20.0
🚀 awesome-react-components
An Awesome React Library for Utility Components and Hooks.
Installation
For npm users
$ npm install awesome-react-components
For pnpm users
$ pnpm install awesome-react-components
For yarn users
$ yarn add awesome-react-components
Components
If
- A replacement of ternary operator for rendering the components
Prop | Type | Required | Default | Description |
---|---|---|---|---|
condition | any | ❌ | false | Based on evaluation of the condition flag the component will return null or children |
children | ReactNode | ❌ | null | To render the children |
suspense | boolean | ❌ | false | To lazy load the component or not |
fallback | ReactNode | ❌ | Fragment | Fallback needed to show unless the component is loaded fully for suspensed components |
Working
- If you pass only one children and condition is false then it will return null otherwise the childen will be rendered.
- If you pass two or more childs and condition is false then it will return all of the children except first child otherwise the first child will be rendered.
Example
import { If } from 'awesome-react-components';
// For react lazy loading
import { lazy } from 'react';
const SomeLazyComponent = lazy(() => import('./some-lazy-component'));
// For nextjs lazy loading
import dynamic from 'next/dynamic';
const SomeLazyComponent = dynamic(() => import('./some-lazy-component'), { ssr: false });
export default function YourComponent() {
return (
<div>
{/* Passing only one children and a condition prop */}
<If codition={true}>
<h1>this will render.</h1>
</If>
{/* Passing more than one children and a truthy condition prop */}
<If codition={true}>
<h1>this is will render</h1>
<h2>this is will not render. As condition it truthy, the first children will render</h2>
</If>
{/* Passing more than one children and a falsy condition prop */}
<If codition={falsy}>
<h1>this is will not render</h1>
<h2>this is will render. As condition it falsy, then second children will render</h2>
<h2>this is will also render</h2>
</If>
{/* Passing two childrens, condition and suspense prop */}
<If codition={false} suspense>
{/* this component code file will only download when the condition will be true.
In this case, codition is falsy then it will not be downloaded. */}
<SomeLazyComponent />
<h2>this is will render</h2>
</If>
</div>
);
}
Then
- Takes the children and renders that children
Prop | Type | Required | Default | Description |
---|---|---|---|---|
children | ReactNode | ❌ | null | Renders the passed children |
Example
import { If, Then } from 'awesome-react-components';
export default function YourComponent() {
return (
<div>
<If codition={true}>
<Then>
<h1>this will render.</h1>
</Then>
</If>
</div>
);
}
Else
- Takes the children and renders that children
Prop | Type | Required | Default | Description |
---|---|---|---|---|
children | ReactNode | ❌ | null | Renders the passed children |
Example
import { If, Then, Else } from 'awesome-react-components';
export default function YourComponent() {
return (
<div>
<If codition={true}>
<Then>
<h1>this will render.</h1>
</Then>
</If>
<If codition={true}>
<Then>
<h1>this will render.</h1>
</Then>
<Else>
<h1>this will not render.</h1>
</Else>
</If>
</div>
);
}
For
- Use this component instead of Array.map() for rendering the component
Prop | Type | Required | Default | Description |
---|---|---|---|---|
loop | number | ❌ | 0 | Needed to run the loop |
children | ReactNode | ❌ | null | Renders the passed children |
Example
import { For } from 'awesome-react-components';
import CardComponent from './CardComponent';
export default function YourComponent() {
const Data = [
{ id: 1, course: 'Javascript' },
{ id: 2, course: 'React' },
];
return (
<div>
<For loop={Data.length}>
{(i) => {
return <CardComponent key={Data[i].id}>{Data[i].course}</CardComponent>;
}}
</For>
</div>
);
}
0.20.0
2 years ago
0.19.1
2 years ago
0.19.2
2 years ago
0.20.0-next.0
2 years ago
0.19.0
2 years ago
0.18.0
2 years ago
0.17.0
2 years ago
0.16.0
2 years ago
0.15.0
2 years ago
0.14.0
2 years ago
0.13.0
2 years ago
0.12.0-next.0
2 years ago
0.11.0
2 years ago
0.10.0
2 years ago
0.9.0
2 years ago
0.8.0
2 years ago
0.7.0
2 years ago
0.6.0
2 years ago
0.5.0
2 years ago
0.4.0
2 years ago
0.3.0
2 years ago
0.2.0
2 years ago
0.1.0
2 years ago