-1

I'm sending token from my API and storing it in the cookie inside the browser. I want to access that token with my frontend app using react. Can somebody tell me how to do it

1 Answers1

0

you have a libary in react: react-cookie but js-cookie is better.

react-cookie: https://www.npmjs.com/package/react-cookie

js-cookie: https://www.npmjs.com/package/js-cookie

you can get your cookies when you need example: By using a useEffect or onClick.

example:

import React, { useState } from 'react';
import Cookies from 'js-cookie';

function App() {
     const [cookies, setCookies] = useState({
        username: Cookies.get('username')
     })
} 
Faranix
  • 11
  • 2