0.0.4 ā€¢ Published 2 years ago

@icastro085/react-canrender v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Welcome to @icastro085/react-canrender šŸ‘‹

ci Version Prerequisite Documentation Maintenance

A small component to help render other components according a condition

Install

npm

npm i @icastro085/react-canrender

yarn

yarn add @icastro085/react-canrender

Usage example

Take a look at the following presentational component, which contains a commonly used pattern for conditional rendering:

const Container = ({ name }) => (
  <div>
    {name ? <span>My name is {name}!</span> : <span>Sorry, the name is missing.</span>}
  </div>
);

With React-CanRender you can rewrite this into a more readable:

const Container = ({ name }) => (
  <CanRender when={name?.length}>
    My name is {name}!
    <ElseRender>Sorry, the name is missing.</ElseRender>
  </CanRender>
);

CanRender

const Container = () => (
  <CanRender when={true}>
    Content to render when condition is true
  </CanRender>
);

ElseRender

const Container = () => (
  <CanRender when={false}>
    It will not render
    <ElseRender>Render when condition is false.</ElseRender>
  </CanRender>
);

ElseCanRender

const Container = () => (
  <CanRender when={false}>
    It will not render
    <ElseCanRender when={true}>
      Render when condition is false of parent and condition for it is true.
    </ElseCanRender>
    <ElseRender>It will not render.</ElseRender>
  </CanRender>
);

Run tests

yarn test

Author

šŸ‘¤ Ivanildo de Castro ivanildo.decastro085@gmail.com

šŸ¤ Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ā­ļø if this project helped you!

šŸ“ License

Copyright Ā© 2021 Ivanildo de Castro <ivanildo.decastro085@gmail.com>.

This project is MIT licensed.


This README was generated with ā¤ļø by readme-md-generator