Created
February 7, 2023 06:44
-
-
Save Manntrix/6993deb977f17ae4df0eab5ae812ad91 to your computer and use it in GitHub Desktop.
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
import Cookies from "js-cookie"; | |
function App() { | |
// Method to set data in cookies which will expire in 7 days | |
const SetCookie = () => { | |
Cookies.set("token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9", { | |
expires: 7, | |
}); | |
}; | |
// Method to get data from cookies | |
const GetCookie = () => { | |
alert(Cookies.get("token")); | |
}; | |
// Method to remove data from cookies | |
const RemoveCookie = () => { | |
Cookies.remove("token"); | |
}; | |
return ( | |
<div style={{ textAlign: "center" }}> | |
<h6>1. Click on Set Cookie to set data in cookies</h6> | |
<h6>2. Click on Get Cookie to display the data</h6> | |
<h6>2. Click on Remove Cookie to remove data from cookies</h6> | |
<button onClick={SetCookie}>Set Cookie</button> | |
<button onClick={GetCookie}>Get Cookie</button> | |
<button onClick={RemoveCookie}>Remove Cookie</button> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment