I am an angular dev who is new to React. I use observables to manage all my states as that is what I am familiar with. I am trying to figure out the best way to write a custom observable hook that only subscribes when the user clicks a button
I am trying to implement something like this:
const addMovieHandler = useCallback((movie) => {
setIsLoading(true);
addMovie$(movie).subscribe((data) => {
console.log(data);
fetchMovies()
});
}, [fetchMovies]);
It works but it seems hacky and I do not know where to put the unsubscribe