recks
  • Intro to RecksJS
  • Install
  • API
    • Lifecycle
    • Events
    • Subcomponents
    • Lists
    • DOM references
  • Libraries
    • State
  • GitHub
  • Playground
Powered by GitBook
On this page

Was this helpful?

  1. API

Events

PreviousLifecycleNextSubcomponents

Last updated 4 years ago

Was this helpful?

To listen to DOM events you simply need to prepend event name with on prefix:

<button
  onClick={ handler }
>
  click me
</button>

handler would receive native .

NOTE: on MDN

Events and Subjects

The best way to use events in you Recks components — is to push them into a local RxJS Subject:

function App() {
  // events stream
  const input$ = new Subject();

  // accumulating stream
  const times$ = input$.pipe(
    startWith(0),
    scan(acc => ++acc)
  );

  return (
      <button onClick={ () => input$.next() }>
        Clicks: { times$ }
      </button>
  );
}

Event
DOM event list
online sandbox