react-request-hook icon indicating copy to clipboard operation
react-request-hook copied to clipboard

useResource not accepting configuration

Open samithbharadwaj opened this issue 5 years ago • 2 comments

I have a ReactJS project created using the create-react-app utility and I've setup react-request-hook as follows.

Only index.jsx (P.S no App.jsx):

const axiosInstance = axios.create({
  baseURL: 'http://someurl',
})
ReactDOM.render(
  <RequestProvider value={axiosInstance}>
    <Router />
  </RequestProvider>,
  document.getElementById('root'),
)

I have written a single API for login which is a POST call

const api = {
  loginUser: async ({
    username,
    password,
    language,
  }) => {
    return request({
      method: 'post',
      url: '/login',
      data: {
        username,
        password,
        language,
        requestId: 'LOGIN',
      },
    })
  },
}

And this is how I'm using it.

const [response] = useResource(api.loginUser,
    [{
      username: 'test',
      password: 'test',
      language: 'en',
    }])

When I run the react app, a request is made only to the base URL and the request type is 'GET" Looks like my data or URL is not accepted as an argument along with the Axios config instance.

Any ideas on what I'm doing wrong? @schettino

samithbharadwaj avatar Oct 08 '19 18:10 samithbharadwaj

Did you figure it out how to fix it, @samithbharadwaj ?

oldmember avatar Oct 14 '19 13:10 oldmember

@oldmember No, I couldn't figure it out. Any ideas?

samithbharadwaj avatar Oct 15 '19 06:10 samithbharadwaj