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

  onClick={ handler }
  click me

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(
    scan(acc => ++acc)

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

online sandbox

Last updated