@storybook/addons#useState TypeScript Examples
The following examples show how to use
@storybook/addons#useState.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: default.tsx From use-platform with MIT License | 6 votes |
Default = (args: DefaultArgs) => {
const { bind, disabled } = args
const [events, setEvents] = useState<string[]>([])
const onAction = useCallback(
(event: KeyboardEvent) => {
setEvents(events.concat(`Key: ${event.code}, timestamp: ${Date.now()}`))
},
[events],
)
useKeyBinding({ bind, disabled, onAction: onAction })
return (
<div>
{events.length === 0 && <div>No events were detected yet</div>}
{events.map((ev) => (
<div key={ev}>{ev}</div>
))}
</div>
)
}
Example #2
Source File: TextField.stories.tsx From atlas with GNU General Public License v3.0 | 5 votes |
TemplateWithControlledInput: Story<TextFieldProps> = (args) => {
const [value, setValue] = useState('')
return <TextField {...args} onChange={(e) => setValue(e.target.value)} value={value} />
}