File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -440,13 +440,16 @@ import { Provider } from 'use-http'
440
440
import { toCamel } from ' convert-keys'
441
441
442
442
function App () {
443
- let [token] = useLocalStorage (' token' )
443
+ let [token, setToken ] = useLocalStorage (' token' )
444
444
445
445
const options = {
446
446
interceptors: {
447
447
// every time we make an http request, this will run 1st before the request is made
448
448
request: async (options ) => {
449
- if (isExpired (token)) token = await getNewToken ()
449
+ if (isExpired (token)) {
450
+ token = await getNewToken ()
451
+ setToken (token)
452
+ }
450
453
options .headers .Authorization = ` Bearer ${ token} `
451
454
return options
452
455
},
Original file line number Diff line number Diff line change @@ -53,6 +53,8 @@ Features
53
53
- Provider to set default ` url ` and ` options `
54
54
- Request/response interceptors <!-- https://github.com/alex-cory/use-http#user-content-interceptors-->
55
55
- React Native support
56
+ - Aborts/Cancels pending http requests when a component unmounts
57
+
56
58
57
59
Examples
58
60
=========
@@ -263,13 +265,16 @@ import { Provider } from 'use-http'
263
265
import { toCamel } from ' convert-keys'
264
266
265
267
function App () {
266
- let [token] = useLocalStorage (' token' )
268
+ let [token, setToken ] = useLocalStorage (' token' )
267
269
268
270
const options = {
269
271
interceptors: {
270
272
// every time we make an http request, this will run 1st before the request is made
271
273
request: async (options ) => {
272
- if (isExpired (token)) token = await getNewToken ()
274
+ if (isExpired (token)) {
275
+ token = await getNewToken ()
276
+ setToken (token)
277
+ }
273
278
options .headers .Authorization = ` Bearer ${ token} `
274
279
return options
275
280
},
You can’t perform that action at this time.
0 commit comments