Skip to content

Commit

Permalink
Convert @emotion/use-insertion-effect-with-fallbacks's source code …
Browse files Browse the repository at this point in the history
…to TypeScript (#3279)
  • Loading branch information
Andarist authored Dec 3, 2024
1 parent c161e6f commit e1bf17e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-suits-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@emotion/use-insertion-effect-with-fallbacks': minor
---

Source code has been migrated to TypeScript. From now on type declarations will be emitted based on that, instead of being hand-written.
11 changes: 6 additions & 5 deletions packages/use-insertion-effect-with-fallbacks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "A wrapper package that uses `useInsertionEffect` or a fallback for it",
"main": "dist/emotion-use-insertion-effect-with-fallbacks.cjs.js",
"module": "dist/emotion-use-insertion-effect-with-fallbacks.esm.js",
"types": "dist/emotion-use-insertion-effect-with-fallbacks.cjs.d.ts",
"license": "MIT",
"repository": "https://github.com/emotion-js/emotion/tree/main/packages/use-insertion-effect-with-fallbacks",
"publishConfig": {
Expand Down Expand Up @@ -53,11 +54,11 @@
},
"imports": {
"#is-browser": {
"edge-light": "./src/conditions/false.js",
"workerd": "./src/conditions/false.js",
"worker": "./src/conditions/false.js",
"browser": "./src/conditions/true.js",
"default": "./src/conditions/is-browser.js"
"edge-light": "./src/conditions/false.ts",
"workerd": "./src/conditions/false.ts",
"worker": "./src/conditions/false.ts",
"browser": "./src/conditions/true.ts",
"default": "./src/conditions/is-browser.ts"
}
}
}
15 changes: 0 additions & 15 deletions packages/use-insertion-effect-with-fallbacks/src/index.js

This file was deleted.

21 changes: 21 additions & 0 deletions packages/use-insertion-effect-with-fallbacks/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as React from 'react'
import isBrowser from '#is-browser'

const syncFallback = <T>(create: () => T) => create()

const useInsertionEffect = React[
('useInsertion' + 'Effect') as 'useInsertionEffect'
]
? (React[('useInsertion' + 'Effect') as 'useInsertionEffect'] as <T>(
create: () => T
) => T | undefined)
: false

export const useInsertionEffectAlwaysWithSyncFallback: <T>(
create: () => T
) => T | undefined = !isBrowser
? syncFallback
: useInsertionEffect || syncFallback

export const useInsertionEffectWithLayoutFallback: typeof React.useLayoutEffect =
useInsertionEffect || React.useLayoutEffect

0 comments on commit e1bf17e

Please sign in to comment.