Skip to content

Commit

Permalink
Code style fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
trekhleb committed Apr 19, 2020
1 parent 8d7b271 commit 0db4fe7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
9 changes: 8 additions & 1 deletion demo/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ export const Demo = ({watch, settings}) => {
error,
} = usePosition(watch, settings);

const loader = !latitude && !error ? (
<>
<div>Trying to fetch location...</div>
<br/>
</>
) : null;

return (
<>
{!latitude && !error && <><div>Trying to fetch location...</div><br/></>}
{loader}
<code>
latitude: {latitude}<br/>
longitude: {longitude}<br/>
Expand Down
9 changes: 7 additions & 2 deletions src/usePosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ export const usePosition = (watch = false, settings = defaultSettings) => {

let watcher = null;
if (watch) {
watcher = navigator.geolocation.watchPosition(onChange, onError, settings);
watcher =
navigator.geolocation.watchPosition(onChange, onError, settings);
} else {
navigator.geolocation.getCurrentPosition(onChange, onError, settings);
}

return () => watcher && navigator.geolocation.clearWatch(watcher);
}, [settings.enableHighAccuracy, settings.timeout, settings.maximumAge]);
}, [
settings.enableHighAccuracy,
settings.timeout,
settings.maximumAge,
]);

return {...position, error};
};
14 changes: 7 additions & 7 deletions stories/index.stories.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import {storiesOf} from '@storybook/react';
import {Demo} from '../demo/Demo';
import { storiesOf } from '@storybook/react';
import { Demo } from '../demo/Demo';

const highAccuracySettings = {
enableHighAccuracy: true,
};

storiesOf('usePosition', module)
.add('fetching', () => <Demo />)
.add('watching', () => <Demo watch />)
.add('high accuracy watching', () => (
<Demo watch settings={highAccuracySettings} />
));
.add('fetching', () => <Demo/>)
.add('watching', () => <Demo watch/>)
.add('high accuracy watching', () => (
<Demo watch settings={highAccuracySettings}/>
));

0 comments on commit 0db4fe7

Please sign in to comment.