rest-hooks | Delightful data fetching for React | Frontend Framework library
kandi X-RAY | rest-hooks Summary
kandi X-RAY | rest-hooks Summary
Asynchronous dynamic data at scale. Performance, data integrity, and typing for REST, proto, GraphQL, websockets and more.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of rest-hooks
rest-hooks Key Features
rest-hooks Examples and Code Snippets
Community Discussions
Trending Discussions on rest-hooks
QUESTION
I am trying to build the authentication part of my frontend project so it can communicate with the DRF API. I decided also to use rest-hooks to fetch and send data from / to the API.
I am reading rest-hooks auth documentation as a guide but I can't find the "proper way" to implement it in my project. Everything I have read so far is using resources to fetch and send data to the API.
In the backend I have this /api-auth
endpoint that after sending username
& password
parameters it returns a token to use as a header while fetching, I guess this is the "easy" part.
Despite I am trying to understand the rest-hooks documentation I can't figure out how to bring this together using DRF API + rest-hooks.
And plus, besides everything I have said above, I have tried this anyway, and is not working...
AttemptsI created this AuthResource
to attach to the login form.
fetch
approach:
...ANSWER
Answered 2021-Apr-05 at 02:27Type 'string' is not assignable to type 'RequestCredentials | undefined'.
Typescript infers the return type of getFetchInit
as having the property { credentials: string }
because it sees 'same-origin'
as just string
. The expected return type RequestInit
only allows for specific literal strings in the union type RequestCredentials
. 'same-origin'
is one of those strings, so the value is fine. We just need to get Typescript to interpret it more specifically than string
.
One way to do this is by using an as const
assertion, which means that the return type includes the literal value of the string { credentials: 'same-origin' }
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install rest-hooks
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page