
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
react-smart-conditional
Advanced tools
Manage conditional rendering in react js and it's frameworks like a pro
A flexible and reusable React component for conditional rendering.
If
componentsElse
componentpnpm install react-smart-conditional
The following example demonstrates the traditional way of conditional rendering in React using ternary operators and logical AND operators. While functional, this approach can become difficult to read and maintain as the number of conditions increases.
import React from 'react';
const DataDisplay = ({ isLoading, error, data }) => {
return (
<div>
{isLoading ? (
<p>Loading...</p>
) : error ? (
<p>Error: {error.message}</p>
) : data ? (
<div>
<h1>Data Loaded:</h1>
<pre>{JSON.stringify(data, null, 2)}</pre>
</div>
) : (
<p>No data available.</p>
)}
</div>
);
};
export default DataDisplay;
This example showcases the same component using the react-smart-conditional
library. The Show
component and its child components (If
, and Else
) provide a more declarative and readable approach to conditional rendering, especially for complex scenarios.
import React from 'react';
import { Show } from 'react-smart-conditional';
const DataDisplay = ({ isLoading, error, data }) => {
return (
<Show as="section">
<Show.If condition={isLoading}>Loading...</Show.If>
<Show.If condition={error}>Error: {error.message}</Show.If>
<Show.If condition={data}>
<h1>Data Loaded:</h1>
<pre>{JSON.stringify(data, null, 2)}</pre>
</Show.If>
<Show.Else>
<p>No data available.</p>
</Show.Else>
</Show>
);
};
export default DataDisplay;
To render all true conditions, use the multiple
prop:
<Show multiple>
<Show.If condition={condition1}>Content for condition 1</Show.If>
<Show.If condition={condition2}>Content for condition 2</Show.If>
<Show.Else>Fallback content</Show.Else>
</Show>
This will render both condition1
and condition2
if they are true.
Show
- Main container for conditional rendering
multiple
: boolean (default: false) - When true, renders all true conditions. When false, renders only the first true condition.as?: string | React.ComponentType
- Wrapper element/component (optional, default: React.Fragment)children: React.ReactNode
- Should contain If
, ElseIf
, and Else
components.Show.If
- Renders children when condition is true
as?: string | React.ComponentType
- Wrapper element/component (optional, default: div)condition: boolean
- Condition to evaluate (required)children: React.ReactNode
- Content to render if trueShow.Else
- Renders when all previous conditions were false
as?: string | React.ComponentType
- Wrapper element/component (optional, default: div)children: React.ReactNode
- Content to renderThe Show
, Show.If
, and Show.Else
components support polymorphic rendering:
<Show as="section" className="container" data-testid="show-container">
<Show.If
condition={true}
as="p"
className="content active"
onClick={() => console.log('Clicked')}
>
Paragraph content
</Show.If>
<Show.If
condition={false}
as="div"
className="content inactive"
style={{ display: 'none' }}
>
Hidden content
</Show.If>
<Show.Else as="span" className="fallback" aria-label="Fallback content">
Span content
</Show.Else>
</Show>
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)If you find this project helpful, please consider giving it a star on GitHub! ⭐️
Distributed under the MIT License. See LICENSE
for more information.
Made with ❤️ Wilson Adenuga - @Adenugawilson - oluwatunmiseadenuga@gmail.com
Project Link: https://github.com/oluwatunmiisheii/react-smart-conditional
[1.0.4] - 2025-03-05
FAQs
Manage conditional rendering in react js and it's frameworks like a pro
The npm package react-smart-conditional receives a total of 345 weekly downloads. As such, react-smart-conditional popularity was classified as not popular.
We found that react-smart-conditional demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.