fix Subscribe running in react18 StrictMode (#249)

This commit is contained in:
Victor Oliva 2022-03-30 14:45:44 +02:00 committed by GitHub
parent fb7004a066
commit da4c7c6c30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -1,7 +1,15 @@
import { render } from "@testing-library/react"
import React, { useState } from "react"
import React, { StrictMode, useState } from "react"
import { defer, Observable, of } from "rxjs"
import { bind, Subscribe } from "./"
import { bind, Subscribe as OriginalSubscribe } from "./"
const Subscribe = (props: any) => {
return (
<StrictMode>
<OriginalSubscribe {...props} />
</StrictMode>
)
}
describe("Subscribe", () => {
describe("Subscribe with source$", () => {

View File

@ -77,6 +77,7 @@ export const Subscribe: React.FC<{
useEffect(() => {
return () => {
subscriptionRef.current!.unsubscribe()
subscriptionRef.current = undefined
}
}, [])