Skip to content

Commit e1bf17e

Browse files
authored
Convert @emotion/use-insertion-effect-with-fallbacks's source code to TypeScript (#3279)
1 parent c161e6f commit e1bf17e

File tree

7 files changed

+32
-20
lines changed

7 files changed

+32
-20
lines changed

.changeset/grumpy-suits-cough.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@emotion/use-insertion-effect-with-fallbacks': minor
3+
---
4+
5+
Source code has been migrated to TypeScript. From now on type declarations will be emitted based on that, instead of being hand-written.

packages/use-insertion-effect-with-fallbacks/package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "A wrapper package that uses `useInsertionEffect` or a fallback for it",
55
"main": "dist/emotion-use-insertion-effect-with-fallbacks.cjs.js",
66
"module": "dist/emotion-use-insertion-effect-with-fallbacks.esm.js",
7+
"types": "dist/emotion-use-insertion-effect-with-fallbacks.cjs.d.ts",
78
"license": "MIT",
89
"repository": "https://github.com/emotion-js/emotion/tree/main/packages/use-insertion-effect-with-fallbacks",
910
"publishConfig": {
@@ -53,11 +54,11 @@
5354
},
5455
"imports": {
5556
"#is-browser": {
56-
"edge-light": "./src/conditions/false.js",
57-
"workerd": "./src/conditions/false.js",
58-
"worker": "./src/conditions/false.js",
59-
"browser": "./src/conditions/true.js",
60-
"default": "./src/conditions/is-browser.js"
57+
"edge-light": "./src/conditions/false.ts",
58+
"workerd": "./src/conditions/false.ts",
59+
"worker": "./src/conditions/false.ts",
60+
"browser": "./src/conditions/true.ts",
61+
"default": "./src/conditions/is-browser.ts"
6162
}
6263
}
6364
}

packages/use-insertion-effect-with-fallbacks/src/index.js

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as React from 'react'
2+
import isBrowser from '#is-browser'
3+
4+
const syncFallback = <T>(create: () => T) => create()
5+
6+
const useInsertionEffect = React[
7+
('useInsertion' + 'Effect') as 'useInsertionEffect'
8+
]
9+
? (React[('useInsertion' + 'Effect') as 'useInsertionEffect'] as <T>(
10+
create: () => T
11+
) => T | undefined)
12+
: false
13+
14+
export const useInsertionEffectAlwaysWithSyncFallback: <T>(
15+
create: () => T
16+
) => T | undefined = !isBrowser
17+
? syncFallback
18+
: useInsertionEffect || syncFallback
19+
20+
export const useInsertionEffectWithLayoutFallback: typeof React.useLayoutEffect =
21+
useInsertionEffect || React.useLayoutEffect

0 commit comments

Comments
 (0)