Skip to content

Instantly share code, notes, and snippets.

@lorenzojkrl
Created March 21, 2022 10:14
Show Gist options
  • Save lorenzojkrl/3a78f25fc659bc5d51c3dd75bbb874a0 to your computer and use it in GitHub Desktop.
Save lorenzojkrl/3a78f25fc659bc5d51c3dd75bbb874a0 to your computer and use it in GitHub Desktop.
Create a React component to use RxJS interval - add observable
import React, { useState, useEffect } from 'react';
import './style.css';
import { interval } from 'rxjs';
export default function App() {
const [state, setState] = useState();
const observable$ = interval(1000);
useEffect(() => {
observable$.subscribe((value) => setState(value));
}, []);
return (
<div>
<h1>Hello RxJS!</h1>
<p>Observable value: {state}</p>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment