contiamo / restful-react

A consistent, declarative way of interacting with RESTful backends, featuring code-generation from Swagger and OpenAPI specs 🔥
MIT License
1.87k stars 109 forks source link

provide access to the context values #250

Closed ysgk closed 4 years ago

ysgk commented 4 years ago

Is your feature request related to a problem? Please describe. I want to create a custom hook that uses base value passed to the Context, but currently there is no such functionality provided.

For example:

import { useRestfulContext } from 'restful-react'

const useMyOriginalHook = () => {
  const { base } = useRestfulContext()
  // ... My original request logic
}

Describe the solution you'd like It would be nice if restful-react could provide such a hook or export the Context itself.

Describe alternatives you've considered There seems no alternative unless the Context is exported.

fabien0102 commented 4 years ago

This seams totally overkill, why are you not just exporting base?

export base = "https://my-api.com"

And you are good to go!

If you want something more fancy to deal with you config, I can also suggest https://github.com/contiamo/react-runtime-config 😇 My little homemade solution, works very smoothly 😃

ysgk commented 4 years ago

OK, I'll look into it. Thanks.