Skip to content

Commit

Permalink
fix(react): return type of Delay should be JSX.Element (#898)
Browse files Browse the repository at this point in the history
# Overview

<!--
    A clear and concise description of what this pr is about.
 -->

same reason with previous PRs

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md)
2. I added documents and tests.
  • Loading branch information
manudeli authored May 31, 2024
1 parent 1ec3f22 commit 8c5844b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/honest-peas-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@suspensive/react": patch
---

fix(react): return type of Delay should be JSX.Element
17 changes: 17 additions & 0 deletions packages/react/src/Delay.test-d.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { ReactNode } from 'react'
import { Delay } from './Delay'

describe('<Delay/>', () => {
it('type check', () => {
expectTypeOf(
<Delay>
<></>
</Delay>
).toEqualTypeOf<JSX.Element>()
expectTypeOf(
<Delay>
<></>
</Delay>
).not.toEqualTypeOf<ReactNode>()
})
})
2 changes: 1 addition & 1 deletion packages/react/src/Delay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Delay = (props: DelayProps) => {
useTimeout(() => setIsDelaying(false), ms)

const fallback = typeof props.fallback === 'undefined' ? defaultProps.fallback : props.fallback
return isDelaying ? fallback : props.children
return <>{isDelaying ? fallback : props.children}</>
}
if (process.env.NODE_ENV === 'development') {
Delay.displayName = 'Delay'
Expand Down

0 comments on commit 8c5844b

Please sign in to comment.