Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how add changed headers in GET request #353

Open
ilyanikulin opened this issue Sep 30, 2021 · 2 comments
Open

how add changed headers in GET request #353

ilyanikulin opened this issue Sep 30, 2021 · 2 comments

Comments

@ilyanikulin
Copy link

ilyanikulin commented Sep 30, 2021

Hello!
I need make only one get request with other headers. How can I set Headers in the GET request?

I want make something like this:
`

 const HOCComponent = () => {
     const {get, data} = useFetch('/api');
     const [hasFirstRequest, setHasFirstRequest] = useState(false);

    useEffect(() => {
        get('/users', {
           headers: {
             Prefer: 'count=estimated',
          }
       }).then(() => setHasFirstRequest(true));
   }, [get])

   useEffect(() => {
      if (hasFirstRequest) {
         get('/users')
      }
   }, [hasFirstRequest]);

}

`

@mdenburger
Copy link

Any update on this? I want to do the same thing but it doesn't seem to be possible :(

@ilyanikulin
Copy link
Author

@mdenburger
Hi!
I found this solution:
const { get: getGeneral, loading: loadingGeneral } = useFetch(${endpoint}${params.total}, {
const { get: getFirst, loading: loadingFirst } = useFetch(${endpoint}${params.total}, {
headers: {
Prefer: 'count=estimated',
},
});

I used two useFetch. getFirst is with changed headers and I use getFirst only when I need it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants