Comparing version 0.1.0 to 0.1.1
@@ -184,8 +184,9 @@ import React, { useState, useRef, useEffect } from 'react'; | ||
return function (trackingKeys) { | ||
var _useState = useState(function () { | ||
var _useStateRef = useStateRef(function () { | ||
return pickTrackedValues(initialValues, trackingKeys); | ||
}), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
selected = _useState2[0], | ||
setSelected = _useState2[1]; | ||
_useStateRef2 = _slicedToArray(_useStateRef, 3), | ||
selected = _useStateRef2[0], | ||
setSelected = _useStateRef2[1], | ||
selectedRef = _useStateRef2[2]; | ||
@@ -196,3 +197,3 @@ if (typeof window !== 'undefined') { | ||
var hasChanged = trackingKeys.some(function (key) { | ||
return selected[key] !== nextValue[key]; | ||
return selectedRef.current[key] !== nextValue[key]; | ||
}); | ||
@@ -199,0 +200,0 @@ |
@@ -191,8 +191,9 @@ 'use strict'; | ||
return function (trackingKeys) { | ||
var _useState = React.useState(function () { | ||
var _useStateRef = useStateRef(function () { | ||
return pickTrackedValues(initialValues, trackingKeys); | ||
}), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
selected = _useState2[0], | ||
setSelected = _useState2[1]; | ||
_useStateRef2 = _slicedToArray(_useStateRef, 3), | ||
selected = _useStateRef2[0], | ||
setSelected = _useStateRef2[1], | ||
selectedRef = _useStateRef2[2]; | ||
@@ -203,3 +204,3 @@ if (typeof window !== 'undefined') { | ||
var hasChanged = trackingKeys.some(function (key) { | ||
return selected[key] !== nextValue[key]; | ||
return selectedRef.current[key] !== nextValue[key]; | ||
}); | ||
@@ -206,0 +207,0 @@ |
@@ -190,8 +190,9 @@ (function (global, factory) { | ||
return function (trackingKeys) { | ||
var _useState = React.useState(function () { | ||
var _useStateRef = useStateRef(function () { | ||
return pickTrackedValues(initialValues, trackingKeys); | ||
}), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
selected = _useState2[0], | ||
setSelected = _useState2[1]; | ||
_useStateRef2 = _slicedToArray(_useStateRef, 3), | ||
selected = _useStateRef2[0], | ||
setSelected = _useStateRef2[1], | ||
selectedRef = _useStateRef2[2]; | ||
@@ -202,3 +203,3 @@ if (typeof window !== 'undefined') { | ||
var hasChanged = trackingKeys.some(function (key) { | ||
return selected[key] !== nextValue[key]; | ||
return selectedRef.current[key] !== nextValue[key]; | ||
}); | ||
@@ -205,0 +206,0 @@ |
@@ -1,3 +0,3 @@ | ||
import { ContextableStates } from 'packages/create'; | ||
import { ContextableStates } from './create'; | ||
declare const makeUseTracked: <T extends ContextableStates>(initialValues: T, eventName: string) => (trackingKeys: (keyof T)[]) => { [key in keyof T]: T[key]; }; | ||
export default makeUseTracked; |
{ | ||
"name": "backset", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "dist/index.js", | ||
@@ -70,2 +70,2 @@ "module": "dist/index.es.js", | ||
"dependencies": {} | ||
} | ||
} |
@@ -18,16 +18,20 @@ ## Backset | ||
```jsx | ||
import Backset from 'backset' | ||
const { useStores, useUpdates } = Backset.create({ title: 'Hello World' }) | ||
import { create } from 'backset' | ||
const { useStores, useUpdates, withContext } = create({ title: 'Hello World' }) | ||
const Page1 = () => { | ||
const Child = () => { | ||
const updates = useUpdates() | ||
return <button onClick={() => updates.title('Hello Backset')}>Edit</button> | ||
} | ||
const App = () => { | ||
const { title } = useStores() | ||
return <span>{title}</span> | ||
return <div>{title} <Child /></div> | ||
} | ||
const Page2 = () => { | ||
const updates = useUpdates() | ||
return <button onClick={() => updates.title('Hello Backset')}>Edit</button> | ||
} | ||
export default withContext(App) | ||
``` | ||
[Edit this example on codesandbox](https://codesandbox.io/s/backset-quick-start-xj1p9?file=/src/index.js). | ||
### Documentation | ||
@@ -34,0 +38,0 @@ |
32545
756
43