-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support withCredentials in useEventSource()
- Loading branch information
Showing
1 changed file
with
6 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
If you pass an object as
init
the hook will call close/open every render because theinit
object is a by-reference dependency of the useEffect. MDN currently only documents one possible option:withCredentials: boolean;
.In this PR I just handle
withCredentials
specially. An alternative would be to just removeinit
from the dependency array because changing it after creating theEventSource
doesn't make sense. Another possible solution is to useJSON.stringify()
outside theuseEffect
andJSON.parse()
inside the useEffect.