
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
react-div-with-class
Advanced tools
react-div-with-class is a Higher-Order Component* that returns a div element with whatever class you'd like. It can be used to aid in crafting much more readable JSX.
Here's some JSX for a sidebar component:
<div className="sidebar">
<div className="sidebar-item">
<div className="sidebar-item-title">
Something
</div>
...
</div>
<div className="sidebar-item">
<div className="sidebar-item-title">
Something Else
</div>
...
</div>
</div>
While this code is technically fine, something like this would be much more readable:
<Sidebar>
<Item>
<Title>Something</Title>
...
</Item>
<Item>
<Title>Something Else</Title>
...
</Item>
</Sidebar>
Of course, we could accomplish this by manually creating very simple React components named Sidebar,Item and Title.
That process is made trivial & speedy by using react-div-with-class. We can generate those components with the following code:
import divWithClass from 'react-div-with-class'
const Sidebar = divWithClass('sidebar')
const Item = divWithClass('sidebar-item')
const Title = divWithClass('sidebar-item-title')
react-div-with-class works like you'd hope it would. Any props passed to components it generates are passed through to the underlying div elements.
Class names are concatenated as you'd expect. So, following our previous example, the component:
<Sidebar className="sidebar-collapsed" />
would be a div with the className sidebar sidebar-collapsed.
The code behind divWithClass() is just ~10 lines long - the primary purpose of this repo is to demonstrate how aliasing div elements can result in much easier to read markup.
That being said - feel free to use it in your projects. I use it in mine and has only a peer dependency of React.
Tests are done with Jest via npm test.
––
* I don't know if this technically qualifies as a HOC, since, while it returns a component, it doesn't take one.
FAQs
A React HOC to help you write cleaner code.
We found that react-div-with-class demonstrated a not healthy version release cadence and project activity because the last version was released 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.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.