Events

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 Event.

NOTE: DOM event list 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>
  );
}

online sandbox

Last updated