@solid-primitives/event-props
Version:
Primitive to manage events in a reactive way.
47 lines (30 loc) • 1.25 kB
Markdown
<p>
<img width="100%" src="https://assets.solidjs.com/banner?type=Primitives&background=tiles&project=Event%20Props" alt="Solid Primitives Event Props">
</p>
# @solid-primitives/event-props
[](https://bundlephobia.com/package/@solid-primitives/event-props)
[](https://www.npmjs.com/package/@solid-primitives/event-props)
A helpful primitive that creates the event props and a reactive store with the latest events
## Installation
```bash
npm install @solid-primitives/event-props
# or
yarn add @solid-primitives/event-props
```
## How to use it
### createEventProps
Receive the event props and a props with the latest events:
```ts
const [events, eventProps] = createEventProps('mousedown', 'mousemove', 'mouseup');
const isMouseDown = createMemo(() => (events.mousedown?.ts ?? 0) > (events.mouseup?.ts ?? 1));
createEffect(() => {
if (isMouseDown()) {
console.log(events.mousemove?.clientX, events.mousemove?.clientY);
}
})
<div {...eventProps}>Click and drag on me</div>
```
## Demo
TODO
## Changelog
See [CHANGELOG.md](./CHANGELOG.md)