Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
storybook-controlled
Advanced tools
A simple utility for connecting controlled components to storybook actions, controls and state
A simple utility for connecting controlled components to storybook actions, tests, controls and state
const IncrementorButton = ({count, setCount}) => (
<button onClick={() => setCount(count+1)}>
{count}
</button>
)
const BasicUsage = {
decorators: [makeStateDecorator("onClick", "count")],
}
See the Storybook for more examples
storybook-controlled is meant to be the go-to best practice for writing stories for controlled components in Storybook. It simplifies the process of managing state and actions, allowing developers to create interactive stories that respond to user input seamlessly.
Controlled components often take a value or set of values to display and a callback to update those values. They leave it up to implementers to implement the onChange function and update the passed values. This creates extra flexibility, but causes some issues when it comes to testing.
There are generally two approaches to writing stories for controlled components:
action()/fn()
to mock the callbackThese each have drawbacks. Custom render functions generally break at least some controls, in this case the best case is that the non-functional args are omitted, but often they just don't work. Using storybooks mocks is nice, but you don't get to see the component change in response to user action.
This package introduces a custom Decorator that streamlines the integration between args and callback mocking. By providing a simple interface, the Decorator takes the name of the callback and the state to update as arguments. When applied, it:
The strong TypeScript types prevent common errors, making it easier for developers to implement and use.
FAQs
A simple utility for connecting controlled components to storybook actions, controls and state
We found that storybook-controlled demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.