@tamagui/use-window-dimensions 1.0.1-beta.186 → 1.0.1-beta.188

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -21,22 +21,18 @@ __export(src_exports, {
21
21
  useWindowDimensions: () => useWindowDimensions
22
22
  });
23
23
  module.exports = __toCommonJS(src_exports);
24
- var import_react = require("react");
24
+ var import_use_did_finish_ssr = require("@tamagui/use-did-finish-ssr");
25
25
  var import_react_native = require("react-native");
26
- let lastKnownValue = {
26
+ const initialValue = {
27
27
  fontScale: 1,
28
28
  height: 800,
29
29
  width: 600,
30
30
  scale: 1
31
31
  };
32
32
  function useWindowDimensions() {
33
- const next = (0, import_react_native.useWindowDimensions)();
34
- const [current, setCurrent] = (0, import_react.useState)(lastKnownValue);
35
- if (next !== current) {
36
- setCurrent(next);
37
- lastKnownValue = next;
38
- }
39
- return current;
33
+ const current = (0, import_react_native.useWindowDimensions)();
34
+ const didFinishSSR = (0, import_use_did_finish_ssr.useDidFinishSSR)();
35
+ return didFinishSSR ? current : initialValue;
40
36
  }
41
37
  // Annotate the CommonJS export names for ESM import in node:
42
38
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["import { useState } from 'react'\nimport { ScaledSize, useWindowDimensions as useWindowDimensionsRN } from 'react-native'\n\n/**\n * SSR safe useWindowDimensions\n */\n\nlet lastKnownValue: ScaledSize = {\n fontScale: 1,\n height: 800,\n width: 600,\n scale: 1,\n}\n\nexport function useWindowDimensions() {\n const next = useWindowDimensionsRN()\n const [current, setCurrent] = useState(lastKnownValue)\n\n if (next !== current) {\n setCurrent(next)\n lastKnownValue = next\n }\n\n return current\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyB;AACzB,0BAAyE;AAMzE,IAAI,iBAA6B;AAAA,EAC/B,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AACT;AAEO,SAAS,sBAAsB;AACpC,QAAM,WAAO,oBAAAA,qBAAsB;AACnC,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,cAAc;AAErD,MAAI,SAAS,SAAS;AACpB,eAAW,IAAI;AACf,qBAAiB;AAAA,EACnB;AAEA,SAAO;AACT;",
4
+ "sourcesContent": ["import { useDidFinishSSR } from '@tamagui/use-did-finish-ssr'\nimport { ScaledSize, useWindowDimensions as useWindowDimensionsRN } from 'react-native'\n\n/**\n * SSR safe useWindowDimensions\n */\n\nconst initialValue: ScaledSize = {\n fontScale: 1,\n height: 800,\n width: 600,\n scale: 1,\n}\n\nexport function useWindowDimensions() {\n const current = useWindowDimensionsRN()\n const didFinishSSR = useDidFinishSSR()\n return didFinishSSR ? current : initialValue\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAAgC;AAChC,0BAAyE;AAMzE,MAAM,eAA2B;AAAA,EAC/B,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AACT;AAEO,SAAS,sBAAsB;AACpC,QAAM,cAAU,oBAAAA,qBAAsB;AACtC,QAAM,mBAAe,2CAAgB;AACrC,SAAO,eAAe,UAAU;AAClC;",
6
6
  "names": ["useWindowDimensionsRN"]
7
7
  }
package/dist/esm/index.js CHANGED
@@ -1,19 +1,15 @@
1
- import { useState } from "react";
1
+ import { useDidFinishSSR } from "@tamagui/use-did-finish-ssr";
2
2
  import { useWindowDimensions as useWindowDimensionsRN } from "react-native";
3
- let lastKnownValue = {
3
+ const initialValue = {
4
4
  fontScale: 1,
5
5
  height: 800,
6
6
  width: 600,
7
7
  scale: 1
8
8
  };
9
9
  function useWindowDimensions() {
10
- const next = useWindowDimensionsRN();
11
- const [current, setCurrent] = useState(lastKnownValue);
12
- if (next !== current) {
13
- setCurrent(next);
14
- lastKnownValue = next;
15
- }
16
- return current;
10
+ const current = useWindowDimensionsRN();
11
+ const didFinishSSR = useDidFinishSSR();
12
+ return didFinishSSR ? current : initialValue;
17
13
  }
18
14
  export {
19
15
  useWindowDimensions
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["import { useState } from 'react'\nimport { ScaledSize, useWindowDimensions as useWindowDimensionsRN } from 'react-native'\n\n/**\n * SSR safe useWindowDimensions\n */\n\nlet lastKnownValue: ScaledSize = {\n fontScale: 1,\n height: 800,\n width: 600,\n scale: 1,\n}\n\nexport function useWindowDimensions() {\n const next = useWindowDimensionsRN()\n const [current, setCurrent] = useState(lastKnownValue)\n\n if (next !== current) {\n setCurrent(next)\n lastKnownValue = next\n }\n\n return current\n}\n"],
5
- "mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAqB,uBAAuB,6BAA6B;AAMzE,IAAI,iBAA6B;AAAA,EAC/B,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AACT;AAEO,SAAS,sBAAsB;AACpC,QAAM,OAAO,sBAAsB;AACnC,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,cAAc;AAErD,MAAI,SAAS,SAAS;AACpB,eAAW,IAAI;AACf,qBAAiB;AAAA,EACnB;AAEA,SAAO;AACT;",
4
+ "sourcesContent": ["import { useDidFinishSSR } from '@tamagui/use-did-finish-ssr'\nimport { ScaledSize, useWindowDimensions as useWindowDimensionsRN } from 'react-native'\n\n/**\n * SSR safe useWindowDimensions\n */\n\nconst initialValue: ScaledSize = {\n fontScale: 1,\n height: 800,\n width: 600,\n scale: 1,\n}\n\nexport function useWindowDimensions() {\n const current = useWindowDimensionsRN()\n const didFinishSSR = useDidFinishSSR()\n return didFinishSSR ? current : initialValue\n}\n"],
5
+ "mappings": "AAAA,SAAS,uBAAuB;AAChC,SAAqB,uBAAuB,6BAA6B;AAMzE,MAAM,eAA2B;AAAA,EAC/B,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AACT;AAEO,SAAS,sBAAsB;AACpC,QAAM,UAAU,sBAAsB;AACtC,QAAM,eAAe,gBAAgB;AACrC,SAAO,eAAe,UAAU;AAClC;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/use-window-dimensions",
3
- "version": "1.0.1-beta.186",
3
+ "version": "1.0.1-beta.188",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -18,12 +18,11 @@
18
18
  "clean:build": "tamagui-build clean:build"
19
19
  },
20
20
  "dependencies": {
21
- "@tamagui/use-debounce": "^1.0.1-beta.186",
22
- "@tamagui/use-force-update": "^1.0.1-beta.186",
21
+ "@tamagui/use-did-finish-ssr": "^1.0.1-beta.188",
23
22
  "react": "*"
24
23
  },
25
24
  "devDependencies": {
26
- "@tamagui/build": "^1.0.1-beta.186",
25
+ "@tamagui/build": "^1.0.1-beta.188",
27
26
  "@types/react": "^18.0.15",
28
27
  "react-native": "*"
29
28
  },
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { useState } from 'react'
1
+ import { useDidFinishSSR } from '@tamagui/use-did-finish-ssr'
2
2
  import { ScaledSize, useWindowDimensions as useWindowDimensionsRN } from 'react-native'
3
3
 
4
4
  /**
5
5
  * SSR safe useWindowDimensions
6
6
  */
7
7
 
8
- let lastKnownValue: ScaledSize = {
8
+ const initialValue: ScaledSize = {
9
9
  fontScale: 1,
10
10
  height: 800,
11
11
  width: 600,
@@ -13,13 +13,7 @@ let lastKnownValue: ScaledSize = {
13
13
  }
14
14
 
15
15
  export function useWindowDimensions() {
16
- const next = useWindowDimensionsRN()
17
- const [current, setCurrent] = useState(lastKnownValue)
18
-
19
- if (next !== current) {
20
- setCurrent(next)
21
- lastKnownValue = next
22
- }
23
-
24
- return current
16
+ const current = useWindowDimensionsRN()
17
+ const didFinishSSR = useDidFinishSSR()
18
+ return didFinishSSR ? current : initialValue
25
19
  }