Created
March 21, 2022 10:14
-
-
Save lorenzojkrl/3a78f25fc659bc5d51c3dd75bbb874a0 to your computer and use it in GitHub Desktop.
Create a React component to use RxJS interval - add observable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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