Skip to content

Commit f786dbb

Browse files
committed
Added demo for geolocation hook
1 parent 3165679 commit f786dbb

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/hooks/useGeoLocation.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ const useGeoLocation = () => {
1919
const onError = (error) => {
2020
setLocation({
2121
loaded: true,
22-
error,
22+
error: {
23+
code: error.code,
24+
message: error.message,
25+
},
2326
});
2427
};
2528

src/pages/HooksDemo/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import useFullscreenMode from "hooks/useFullscreenMode";
66
import ExternalInfo from "components/ExternalInfo";
77
import ContactCard from "components/ContactCard";
88
import useVisiblityToggler from "hooks/useVisiblityToggler";
9+
import useGeoLocation from "hooks/useGeoLocation";
910

1011
const HooksDemo = () => {
1112
const [name, setName] = useState("");
1213
const [Prompt, setDirty, setPristine] = useUnsavedChangesWarning();
1314
const [elementRef, FullscreenIcon] = useFullscreenMode();
15+
const location = useGeoLocation();
1416

1517
const [ContactCardComponent, toggleCardVisiblity] = useVisiblityToggler(
1618
<ContactCard index={1} name="D'coders Tech" phone="+959595959595" />,
@@ -96,6 +98,22 @@ const HooksDemo = () => {
9698
</div>
9799
</div>
98100
</div>
101+
102+
<div class="separator">Hook 3: User Geo Location Hook</div>
103+
104+
<div className="row d-flex justify-content-center mt-3 mb-5 pb-5">
105+
<div className="col-6">
106+
<div class="card">
107+
<div class="card-header text-left font-weight-bold d-flex">
108+
<div className="inline-block mr-auto pt-1">
109+
{location.loaded
110+
? JSON.stringify(location)
111+
: "Location data not available yet."}
112+
</div>
113+
</div>
114+
</div>
115+
</div>
116+
</div>
99117
</>
100118
);
101119
};

src/routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const routes = [
8888
enabled: true,
8989
path: "/hooks-demo",
9090
component: HooksDemo,
91-
navbar: "Hooks demo",
91+
navbar: "Custom Hooks demo",
9292
child: null,
9393
},
9494
{

0 commit comments

Comments
 (0)