-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4191fa8
commit 77127e9
Showing
10 changed files
with
576 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { useEffect, useRef } from "react"; | ||
|
||
const CanvasExample = () => { | ||
const canvasRef = useRef(null); | ||
|
||
useEffect(() => { | ||
const canvas = canvasRef.current; | ||
const ctx = canvas.getContext("2d"); | ||
ctx.fillStyle = "red"; | ||
ctx.fillRect(10, 10, 150, 80); | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<h1>Canvas Example</h1> | ||
<canvas | ||
ref={canvasRef} | ||
width="200" | ||
height="100" | ||
style={{ border: "1px solid black" }} | ||
></canvas> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CanvasExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { useState } from "react"; | ||
|
||
const GeolocationExample = () => { | ||
const [location, setLocation] = useState(null); | ||
const [error, setError] = useState(""); | ||
|
||
const getLocation = () => { | ||
if (navigator.geolocation) { | ||
navigator.geolocation.getCurrentPosition( | ||
(position) => { | ||
const { latitude, longitude } = position.coords; | ||
setLocation({ latitude, longitude }); | ||
setError(""); // Clear any previous errors | ||
}, | ||
() => { | ||
setError("Unable to retrieve location."); | ||
} | ||
); | ||
} else { | ||
setError("Geolocation is not supported by this browser."); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h1>Geolocation API Example</h1> | ||
<p>Click the button to get your current location.</p> | ||
<button onClick={getLocation}>Get Location</button> | ||
|
||
<br /> | ||
|
||
{location && ( | ||
<p> | ||
Latitude: {location.latitude} <br /> | ||
Longitude: {location.longitude} | ||
</p> | ||
)} | ||
{error && <p>{error}</p>} | ||
</div> | ||
); | ||
}; | ||
|
||
export default GeolocationExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { useState, useEffect } from "react"; | ||
|
||
const LocalStorageExample = () => { | ||
const [name, setName] = useState(""); | ||
const [message, setMessage] = useState(""); | ||
|
||
// Load saved name from local storage on component mount | ||
useEffect(() => { | ||
const savedName = localStorage.getItem("name"); | ||
if (savedName) { | ||
setMessage(`Welcome back, ${savedName}!`); | ||
} | ||
}, []); | ||
|
||
const saveName = () => { | ||
localStorage.setItem("name", name); | ||
setMessage("Name saved!"); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h1>Local Storage Example</h1> | ||
<p>Enter your name:</p> | ||
<input | ||
type="text" | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
/> | ||
<button onClick={saveName}>Save Name</button> | ||
<p>{message}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LocalStorageExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from "react"; | ||
|
||
const SVGExample = () => { | ||
return ( | ||
<div> | ||
<h1>SVG Example</h1> | ||
<svg width="200" height="100"> | ||
<rect x="10" y="10" width="150" height="80" fill="blue" /> | ||
</svg> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SVGExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { useState, useEffect } from "react"; | ||
|
||
const SessionStorageExample = () => { | ||
const [email, setEmail] = useState(""); | ||
const [message, setMessage] = useState(""); | ||
|
||
// Load saved email from session storage on component mount | ||
useEffect(() => { | ||
const savedEmail = sessionStorage.getItem("email"); | ||
if (savedEmail) { | ||
setMessage(`Your email is ${savedEmail}`); | ||
} | ||
}, []); | ||
|
||
const saveEmail = () => { | ||
sessionStorage.setItem("email", email); | ||
setMessage("Email saved!"); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h1>Session Storage Example</h1> | ||
<p>Enter your email:</p> | ||
<input | ||
type="email" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
/> | ||
<button onClick={saveEmail}>Save Email</button> | ||
<p>{message}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SessionStorageExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.