Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
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")],
}
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
The npm package storybook-controlled receives a total of 7 weekly downloads. As such, storybook-controlled popularity was classified as not popular.
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
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.