score:0
Accepted answer
since it is a react hook, you can't use usecookies
outside a react component function: to access a cookie, you'll need to read it from document.cookie
, or install another package, like cookie.
if you're only using the one cookie, you can probably get away by using w3school's cookie example, (which i've turned into an npm package):
function getcookie(cname) { let name = cname + "="; let decodedcookie = decodeuricomponent(document.cookie); let ca = decodedcookie.split(';'); for(let i = 0; i <ca.length; i++) { let c = ca[i]; while (c.charat(0) == ' ') { c = c.substring(1); } if (c.indexof(name) == 0) { return c.substring(name.length, c.length); } } return ""; }
then just do:
const cookie: string = getcookie('mytoken');
Source: stackoverflow.com
Related Query
- Add cookie to axios interceptor request handler
- How to add global loading/spin effect in axios interceptor for a React project
- Express Session Cookie Not Being Set when using React Axios POST Request
- axios cannot send cookie with request even with withCredential: true
- Axios interceptor retry http request when status is 200 and data is empty
- Axios request interceptor not working on browser refresh
- Howto add pagination with axios get request in Reactjs
- how to make last request in axios response interceptor
- Is it possible to add a Body and and Files to a single Axios request in JS?
- How to add an interceptor to each request to keep ie from caching requests
- axios post request to send form data
- Axios Delete request with body and headers?
- how to cancel/abort ajax request in axios
- How can I add raw data body to an axios request?
- How do I create configuration for axios for default request headers in every http call?
- How to redirect from axios interceptor with react Router V4?
- Make request to SOAP endpoint using axios
- Know if there are pending request in axios
- GraphQL post request in axios
- How can I add a click handler to BODY from within a React component?
- body data not sent in axios request
- Add event handler to React.DOM element dynamically
- Default query params not getting passed in axios request
- How to show progress of Axios during get request (not download or upload)
- axios post request with json data
- React Axios - C# WebAPI request token fails without a server error
- Making redirects after an axios post request with express
- Cancel axios get request when typing reactjs
- Error: Request failed with status code 401 axios in React JS
- Getting 400 error Bad request using axios
More Query from same tag
- Rendering different youtube videos on button click
- I want to disable keyboard input for this date picker how to do that?
- Undefined parameter in react function when retrieving data from API
- javascript verbose react redux
- react type error when fetching new array state
- how to add key and value pair into object with spread function
- Map to element position with pure css
- Setting hook starts infinite loop and app hangs
- ReactJs Global Helper Functions
- Problem while creating Tab in react ERROR (2322)
- React-js and Typescript - Convert connect() to useSelect, useDispatch()
- Toggling an attribute on a ReactJS MaterialUI FloatingButton on click
- Conditionally rendered ref not available in effect that depends on same condition
- Get image from server and preview it on client
- React Router <Component/> vs {Component}
- state values is undefined intially even after being set
- ReactJS Uncaught TypeError: this.refs issue
- Objects are not valid as a React child. If you meant to render a collection of children, use an array instead
- Can't seem to simulate click event with jest
- Disable all checkboxes except "checked" react hooks
- React Router V4 (react-router-dom) navigate programatically deep in the tree
- Best workflow for developing npm packages that depend on each other
- react-google-maps MapWithAMarker fails to rerender when marker position changes
- Storybook main.ts: Cannot use import statement outside a module
- D3 tooltip not updating correctly in a React Component
- When I apply react router to my app, it stops showing all the content
- How to set react createtableselect to prevent creating element not in options?
- Flask get a multi-dimensional array posted to it as an array
- Passing props from different Parent components
- Pass down a function with same name in React