Little update. There is a hook available for react-cookie
1) First of all, install the dependency (just for a note)
yarn add react-cookie
or
npm install react-cookie
2) My usage example:
// SignInComponent.js
import { useCookies } from 'react-cookie'
const SignInComponent = () => {
// ...
const [cookies, setCookie] = useCookies(['access_token', 'refresh_token'])
async function onSubmit(values) {
const response = await getOauthResponse(values);
let expires = new Date()
expires.setTime(expires.getTime() + (response.data.expires_in * 1000))
setCookie('access_token', response.data.access_token, { path: '/', expires})
setCookie('refresh_token', response.data.refresh_token, {path: '/', expires})
// ...
}
// next goes my sign-in form
}
Hope it is helpful.
Suggestions to improve the example above are very appreciated!