- 
Simplifying the way you write conditional and loops in JSX. 
- 
Adding If-Elselike syntax for conditional jsx.
- 
Adding Forcomponent to map over the data within jsx.
- 
Adding Switch-Caseto your jsx.
- Built in Typescript
- Supports Treeshaking
- Small bundle size
- Minimal and Easy to use
- Open Source
For npm users
$ npm install classic-react-componentsFor pnpm users
$ pnpm install classic-react-componentsFor bun users
$ bun install classic-react-componentsFor yarn users
$ yarn add classic-react-components| Prop | Type | Required | Default Value | Description | 
|---|---|---|---|---|
| condition | any | β | false | Based on the evaluation of conditionprop, either children or null will be rendered | 
| children | ReactNode | β | null | Renders the passed children | 
| suspense | boolean | β | false | Used for rendering lazily loaded components | 
| fallback | ReactNode | β | null | Used for showing the fallback until the suspensed children have been loaded. | 
- Based on evaulation of the condition flag the children are rendered.
- If the condition is true then it will render the children otherwise null.
- Working with one child
- If condition is true then child will be rendered.
- If condition is false then null gets rendered.
 
- Working with children(more than one child)
- If condition is true then the first child will be rendered.
- Otherwise the all of the children will be rendered excluding the first child.
 
import { If } from 'classic-react-components'
export default function YourComponent() {
   return (
      <div>
         {/* Passing only one children and a condition prop */}
         <If codition={true}>
            <h1>it will render.</h1>
         </If>
         {/* Passing more than one children and a truthy condition prop */}
         <If codition={false}>
            <h1>it will not render</h1>
            <h2>it will render. As condition it falsy</h2>
         </If>
         {/* Passing more than one children and a falsy condition prop */}
         <If codition={falsy}>
            <h1>it will not render</h1>
            <h2>it will render. As condition it falsy.</h2>
            <h2>it will also render</h2>
         </If>
      </div>
   )
}import { If, Then, Else } from 'classic-react-components'
import { lazy } from 'react'
const YourLazyComponent = lazy(() => import('./YourLazyComponent'))
export default function YourComponent() {
   return (
      <div>
         {/* Passing two children, condition and suspense props */}
         <If codition={false} suspense>
            {/* This component will only download when the condition evaluates to true.
             Here condition is falsy, it will not be downloaded. */}
            <Then>
               <YourLazyComponent />
            </Then>
            <Else>
               <h2>this is will render</h2>
            </Else>
         </If>
      </div>
   )
}   const show = true // some state, which will be toggled to true|false
   // β ternary operator
  { show ? <h1>main content</h1>:<h1>fallback</h1> }
   // β short circuit 
  { show && <h1>main content</h1> }
   // β
 replace ternary
   <If>
      <Then>
         <h1>main content</h1>
      </Then>
      <Else>
         <h1>fallback</h1>
      </Else>
   </If>
   // β
 replace short circuit
   <If>
      <h1>main content</h1>
   </If>| Prop | Type | Required | Default Value | Description | 
|---|---|---|---|---|
| children | ReactNode | β | null | Renders the passed children | 
- It should be used in-conjunction with Ifcommponent.
- It renders the passed children.
import { If, Then } from 'classic-react-components'
export default function YourComponent() {
   return (
      <div>
         <If codition={true}>
            <Then>
               <h1>this will render.</h1>
            </Then>
         </If>
      </div>
   )
}| Prop | Type | Required | Default Value | Description | 
|---|---|---|---|---|
| children | ReactNode | β | null | Renders the passed children | 
- It should be used in-conjunction with Ifcommponent.
- It renders the passed children.
import { If, Then, Else } from 'classic-react-components'
export default function YourComponent() {
   return (
      <div>
         <If codition={2 + 2 == 4}>
            <Then>
               <h1>this will render.</h1>
            </Then>
            <Else>
               <h1>this will not render.</h1>
            </Else>
         </If>
      </div>
   )
}| Prop | Type | Required | Default Value | Description | 
|---|---|---|---|---|
| data | Array | β | undefined | Used for looping over the data and rendering the children | 
| children | ReactNode | β | null | Renders the JSXreturned from child function | 
- Replacement of Array.mapmethod used for rendering the list in jsx.
- Used to iterate over an array of items and renders the JSXbased on the provided child function.
import { For } from 'classic-react-components'
import CardComponent from './CardComponent'
export default function YourComponent() {
   const Data = [
      { id: 1, course: 'Javascript' },
      { id: 2, course: 'React' },
   ]
   return (
      <div>
         <For data={Data}>
            {(item, index) => {
               return <CardComponent key={item.id}>{item.course}</CardComponent>
            }}
         </For>
      </div>
   )
}   const data = [1,2,3]   // some async data
   // β using Array.map to render jsx
   {data.length > 0 && data.map((item, index) => {
      return <CardComponent key={item.id}>{item.course}</CardComponent>
   })}
   // β
 using For component to render jsx without needing to check if data is defined or not
   <For data={data}>
      {(item, index) => {
         return <CardComponent key={item.id}>{item.course}</CardComponent>
      }}
   </For>| Prop | Type | Required | Default Value | Description | 
|---|---|---|---|---|
| item | any | β | undefined | The value used for comparing with all of the cases | 
| children | ReactNode | β | - | Used for rendering the children of matched case if found, else Default Case's children will be rendered | 
- Renders the children of particular matched case for given prop item(switch value).
- If none of cases are matched for given prop item, theDefaultcase will be rendered.
Note: The order of Default Case does not matter.
import { Switch } from 'classic-react-components'
import CardComponent from './CardComponent'
export default function YourComponent({ item }: { item: 'coding' | 'sleep' }) {
   return (
      <div>
         <Switch item={item}>
            {({ Case, Default }) => {
               return (
                  <>
                     <Case value='coding'>
                        <div>coing-case</div>
                     </Case>
                     <Case value='sleep'>
                        <div>sleep-case</div>
                     </Case>
                     <Default>
                        <div>this is default case</div>
                     </Default>
                  </>
               )
            }}
         </Switch>
      </div>
   )
}   const item: "sleep"|"coding" = "sleep"
   // β using old object switching
   // first define seperate object and match the case manually and can not define fallback case here at all
   const itemSwitches = {
      "coding":<div>coing-case</div>,
      "sleep":<div>sleep-case</div>,
   }
   const MatchedCase = itemSwitches(item) ?? <div>fallback</div> // manually giving fallback
   // render in the jsx
   {MatchedCase}
   // β
 using Switch component 
   // much better, we do not have to lookup for the switch logic and jumping between states and jsx unlike with Object switching
   // it support default case if no case is matched. we can not do it in one plase with object switching
   // it is typesafe
   <Switch item={item}>
      {({ Case, Default }) => {
         return (
            <>
               <Case value='coding'>
                  <div>coing-case</div>
               </Case>
               <Case value='sleep'>
                  <div>sleep-case</div>
               </Case>
               <Default>
                  <div>this is default case</div>
               </Default>
            </>
         )
      }}
   </Switch>