@aboutbits/react-toolbox
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -13,10 +13,10 @@ "use strict"; | ||
var data = props.data, error = props.error, _a = props.renderLoading, renderLoading = _a === void 0 ? null : _a, renderSuccess = props.renderSuccess, _b = props.renderError, renderError = _b === void 0 ? null : _b; | ||
var asyncState = asyncState_1.getAsyncState(data, error); | ||
var asyncState = (0, asyncState_1.getAsyncState)(data, error); | ||
switch (asyncState) { | ||
case index_1.AsyncState.FETCHING: | ||
return util_1.isFunction(renderLoading) ? renderLoading() : react_1.default.createElement(react_1.default.Fragment, null, renderLoading); | ||
return (0, util_1.isFunction)(renderLoading) ? renderLoading() : react_1.default.createElement(react_1.default.Fragment, null, renderLoading); | ||
case index_1.AsyncState.FINISHED_WITH_SUCCESS: | ||
return util_1.isFunction(renderSuccess) ? (renderSuccess(data)) : (react_1.default.createElement(react_1.default.Fragment, null, renderSuccess)); | ||
return (0, util_1.isFunction)(renderSuccess) ? (renderSuccess(data)) : (react_1.default.createElement(react_1.default.Fragment, null, renderSuccess)); | ||
case index_1.AsyncState.FINISHED_WITH_ERROR: | ||
return util_1.isFunction(renderError) ? renderError(error) : react_1.default.createElement(react_1.default.Fragment, null, renderError); | ||
return (0, util_1.isFunction)(renderError) ? renderError(error) : react_1.default.createElement(react_1.default.Fragment, null, renderError); | ||
} | ||
@@ -23,0 +23,0 @@ }; |
import { useInterval } from './useInterval/useInterval'; | ||
import { AsyncState, getAsyncState } from './async-data/asyncState'; | ||
import { AsyncView } from './async-data/AsyncView'; | ||
export { useInterval, AsyncState, getAsyncState, AsyncView }; | ||
import { LocationProvider, LocationContext, LocationContextValue } from './location-provider/LocationProvider'; | ||
export { useInterval, AsyncState, getAsyncState, AsyncView, LocationProvider, LocationContext, LocationContextValue, }; |
import { useInterval } from './useInterval/useInterval'; | ||
import { AsyncState, getAsyncState } from './async-data/asyncState'; | ||
import { AsyncView } from './async-data/AsyncView'; | ||
export { useInterval, AsyncState, getAsyncState, AsyncView }; | ||
import { LocationProvider, LocationContext, } from './location-provider/LocationProvider'; | ||
export { useInterval, AsyncState, getAsyncState, AsyncView, LocationProvider, LocationContext, }; |
import { useInterval } from './useInterval/useInterval'; | ||
import { AsyncState, getAsyncState } from './async-data/asyncState'; | ||
import { AsyncView } from './async-data/AsyncView'; | ||
export { useInterval, AsyncState, getAsyncState, AsyncView }; | ||
import { LocationProvider, LocationContext, LocationContextValue } from './location-provider/LocationProvider'; | ||
export { useInterval, AsyncState, getAsyncState, AsyncView, LocationProvider, LocationContext, LocationContextValue, }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AsyncView = exports.getAsyncState = exports.AsyncState = exports.useInterval = void 0; | ||
exports.LocationContext = exports.LocationProvider = exports.AsyncView = exports.getAsyncState = exports.AsyncState = exports.useInterval = void 0; | ||
var useInterval_1 = require("./useInterval/useInterval"); | ||
@@ -11,2 +11,5 @@ Object.defineProperty(exports, "useInterval", { enumerable: true, get: function () { return useInterval_1.useInterval; } }); | ||
Object.defineProperty(exports, "AsyncView", { enumerable: true, get: function () { return AsyncView_1.AsyncView; } }); | ||
var LocationProvider_1 = require("./location-provider/LocationProvider"); | ||
Object.defineProperty(exports, "LocationProvider", { enumerable: true, get: function () { return LocationProvider_1.LocationProvider; } }); | ||
Object.defineProperty(exports, "LocationContext", { enumerable: true, get: function () { return LocationProvider_1.LocationContext; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -6,4 +6,4 @@ "use strict"; | ||
var useInterval = function (callback, delay) { | ||
var savedCallback = react_1.useRef(null); | ||
react_1.useEffect(function () { | ||
var savedCallback = (0, react_1.useRef)(null); | ||
(0, react_1.useEffect)(function () { | ||
if (delay === null) | ||
@@ -13,3 +13,3 @@ return; | ||
}); | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
if (delay === null) | ||
@@ -16,0 +16,0 @@ return; |
{ | ||
"name": "@aboutbits/react-toolbox", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Tools for React", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
React Toolbox | ||
============= | ||
[](https://badge.fury.io/js/%40aboutbits%2Freact-toolbox) | ||
[](https://github.com/aboutbits/react-toolbox/blob/main/license.md) | ||
This package includes different tools that support you with common tasks. | ||
@@ -11,2 +14,3 @@ | ||
- [Async Data](#async-data) | ||
- [LocationProvider](#locationprovider) | ||
- [Build & Publish](#build--publish) | ||
@@ -115,2 +119,36 @@ - [Information](#information) | ||
### LocationProvider | ||
This part includes a React context that fetches the geolocation at a given interval. | ||
```tsx | ||
import { LocationProvider } from '@aboutbits/react-toolbox' | ||
const MyApp = () => { | ||
return ( | ||
<LocationProvider highAccuracy={true} delay={20000}> | ||
{children} | ||
</LocationProvider> | ||
) | ||
} | ||
``` | ||
The context provider takes two props: | ||
- `highAccuracy`: defines if the location should be fetched with high accuracy. Read more on the [Geolocation API doc](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API). | ||
- `delay`: the delay in milliseconds between each fetch | ||
```tsx | ||
import { useContext } from 'react' | ||
import { LocationContext } from '@aboutbits/react-toolbox' | ||
const MyComponent = () => { | ||
const { location } = useContext(LocationContext) | ||
return location | ||
? <div>Your location is: {location.coords.latitude}, {location.coords.longitude}</div> | ||
: <div>Unable to get your location</div> | ||
} | ||
``` | ||
## Build & Publish | ||
@@ -117,0 +155,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
27801
38
361
179