clean up subscription when component unmounts

This commit is contained in:
Bryan Goldstein 2020-04-04 19:45:47 -04:00 committed by GitHub
parent 156b84acee
commit 8ec8e394b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,10 +13,10 @@
const [todos, setTodos] = React.useState({})
React.useEffect(() => {
gun
return gun
.get("todos")
.map()
.on((todo, id) => setTodos(todos => ({...todos, [id]: todo })));
.on((todo, id) => setTodos(todos => ({...todos, [id]: todo }))).off;
}, [])
return (