Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
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: [controlledDecorator("setCount", "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
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.