Skip to content

Instantly share code, notes, and snippets.

@snaga
Created April 17, 2022 03:56
Show Gist options
  • Save snaga/8a267386e5dba8a87724e1b3f1ba7df7 to your computer and use it in GitHub Desktop.
Save snaga/8a267386e5dba8a87724e1b3f1ba7df7 to your computer and use it in GitHub Desktop.
diff --git a/package.json b/package.json
index eeefd0e..067fad2 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
"@testing-library/react": "^13.1.1",
"@testing-library/user-event": "^13.5.0",
"react": "^18.0.0",
+ "react-cookie": "^4.1.1",
"react-dom": "^18.0.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
diff --git a/src/App.js b/src/App.js
index 3784575..2f03b38 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,7 +1,10 @@
import logo from './logo.svg';
import './App.css';
+import { useCookies } from 'react-cookie';
function App() {
+ const [cookies, setCookie, removeCookie] = useCookies(['remote_user']);
+
return (
<div className="App">
<header className="App-header">
@@ -17,6 +20,7 @@ function App() {
>
Learn React
</a>
+ User name: {cookies.remote_user}
</header>
</div>
);
diff --git a/src/index.js b/src/index.js
index d563c0f..dfdbbfa 100644
--- a/src/index.js
+++ b/src/index.js
@@ -3,11 +3,14 @@ import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
+import { CookiesProvider } from 'react-cookie';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
- <App />
+ <CookiesProvider>
+ <App />
+ </CookiesProvider>
</React.StrictMode>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment