chem-rx 0.0.5 → 0.0.7
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/README.md +4 -4
- package/dist/index.cjs.js +6 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.iife.js +6 -1
- package/dist/index.js +6 -1
- package/dist/useHydrateAtoms.d.ts +4 -0
- package/dist/useHydrateAtoms.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/{hydrateAtoms.ts → useHydrateAtoms.ts} +7 -0
- package/dist/hydrateAtoms.d.ts +0 -3
- package/dist/hydrateAtoms.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -247,18 +247,18 @@ function Counter() {
|
|
|
247
247
|
<button onClick={() => count$.set('inner', count + 2)}>one up</button> ...
|
|
248
248
|
```
|
|
249
249
|
|
|
250
|
-
###
|
|
250
|
+
### useHydrateAtoms
|
|
251
251
|
|
|
252
252
|
With SSR, your atoms will likely need to be properly hydrated to prevent
|
|
253
|
-
server/client mismatches. You can use `
|
|
253
|
+
server/client mismatches. You can use `useHydrateAtoms` as a simple solution for
|
|
254
254
|
seeding your client-side Atoms with the correct data.
|
|
255
255
|
|
|
256
256
|
```
|
|
257
|
-
import { Atom, useAtom,
|
|
257
|
+
import { Atom, useAtom, useHydrateAtoms } from 'chem-rx'
|
|
258
258
|
|
|
259
259
|
const count$ = Atom(0)
|
|
260
260
|
const CounterPage = ({ countFromServer }) => {
|
|
261
|
-
|
|
261
|
+
useHydrateAtoms([[count$, countFromServer]])
|
|
262
262
|
const count = useAtom(count$)
|
|
263
263
|
// count would be the value of `countFromServer`, not 0.
|
|
264
264
|
}
|
package/dist/index.cjs.js
CHANGED
|
@@ -254,6 +254,11 @@ function useSelectAtom(atom, key) {
|
|
|
254
254
|
return value;
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
+
function useHydrateAtoms(values) {
|
|
258
|
+
react.useEffect(function () {
|
|
259
|
+
hydrateAtoms(values);
|
|
260
|
+
}, []);
|
|
261
|
+
}
|
|
257
262
|
function hydrateAtoms(values) {
|
|
258
263
|
for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
|
|
259
264
|
var _step$value = _step.value,
|
|
@@ -267,6 +272,6 @@ function Signal() {}
|
|
|
267
272
|
|
|
268
273
|
exports.Atom = Atom;
|
|
269
274
|
exports.Signal = Signal;
|
|
270
|
-
exports.hydrateAtoms = hydrateAtoms;
|
|
271
275
|
exports.useAtom = useAtom;
|
|
276
|
+
exports.useHydrateAtoms = useHydrateAtoms;
|
|
272
277
|
exports.useSelectAtom = useSelectAtom;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Atom } from "./Atom";
|
|
2
2
|
export { useAtom } from "./useAtom";
|
|
3
3
|
export { useSelectAtom } from "./useSelectAtom";
|
|
4
|
-
export {
|
|
4
|
+
export { useHydrateAtoms } from "./useHydrateAtoms";
|
|
5
5
|
export { Signal } from "./Signal";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.iife.js
CHANGED
|
@@ -252,6 +252,11 @@ var chemicalRx = (function (exports, rxjs, react) {
|
|
|
252
252
|
return value;
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
+
function useHydrateAtoms(values) {
|
|
256
|
+
react.useEffect(function () {
|
|
257
|
+
hydrateAtoms(values);
|
|
258
|
+
}, []);
|
|
259
|
+
}
|
|
255
260
|
function hydrateAtoms(values) {
|
|
256
261
|
for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
|
|
257
262
|
var _step$value = _step.value,
|
|
@@ -265,8 +270,8 @@ var chemicalRx = (function (exports, rxjs, react) {
|
|
|
265
270
|
|
|
266
271
|
exports.Atom = Atom;
|
|
267
272
|
exports.Signal = Signal;
|
|
268
|
-
exports.hydrateAtoms = hydrateAtoms;
|
|
269
273
|
exports.useAtom = useAtom;
|
|
274
|
+
exports.useHydrateAtoms = useHydrateAtoms;
|
|
270
275
|
exports.useSelectAtom = useSelectAtom;
|
|
271
276
|
|
|
272
277
|
return exports;
|
package/dist/index.js
CHANGED
|
@@ -176,6 +176,11 @@ function useSelectAtom(atom, key) {
|
|
|
176
176
|
return value;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
function useHydrateAtoms(values) {
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
hydrateAtoms(values);
|
|
182
|
+
}, []);
|
|
183
|
+
}
|
|
179
184
|
function hydrateAtoms(values) {
|
|
180
185
|
for (const [atom, value] of values) {
|
|
181
186
|
atom._behavior$.next(value);
|
|
@@ -184,4 +189,4 @@ function hydrateAtoms(values) {
|
|
|
184
189
|
|
|
185
190
|
function Signal() {}
|
|
186
191
|
|
|
187
|
-
export { Atom, Signal,
|
|
192
|
+
export { Atom, Signal, useAtom, useHydrateAtoms, useSelectAtom };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHydrateAtoms.d.ts","sourceRoot":"","sources":["../src/useHydrateAtoms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,QAItE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,QAInE"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
1
2
|
import { BaseAtom } from "./Atom";
|
|
2
3
|
|
|
4
|
+
export function useHydrateAtoms(values: readonly [BaseAtom<any>, any][]) {
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
hydrateAtoms(values);
|
|
7
|
+
}, []);
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
export function hydrateAtoms(values: readonly [BaseAtom<any>, any][]) {
|
|
4
11
|
for (const [atom, value] of values) {
|
|
5
12
|
atom._behavior$.next(value);
|
package/dist/hydrateAtoms.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hydrateAtoms.d.ts","sourceRoot":"","sources":["../src/hydrateAtoms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,QAInE"}
|