Skip to content

How to wrap a hook with a Provider? #23

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

Closed
stramel opened this issue Mar 28, 2019 · 3 comments
Closed

How to wrap a hook with a Provider? #23

stramel opened this issue Mar 28, 2019 · 3 comments
Labels
question Further information is requested

Comments

@stramel
Copy link

stramel commented Mar 28, 2019

What is your question:

How can I wrap a hook with a necessary Provider?

@stramel stramel added the question Further information is requested label Mar 28, 2019
@mpeyper
Copy link
Member

mpeyper commented Mar 28, 2019

Hi @stramel, you can use the wrapper option of renderHook to wrap the test component in anything you want. An example of using a context Provider can be seen in our test suite

const wrapper = ({ children }) => (
  <YourContext.Provider value="some context">{children}</YourContext.Provider>
)

const { result } = renderHook(() => useYourHook(), { wrapper })

Please feel free to submit a PR improving the docs as some examples are definitely missing.

@stramel
Copy link
Author

stramel commented Mar 28, 2019

@mpeyper Thank you for the answer. This is indeed what I was looking for. I will try to get a PR out for this in the near future.

@mpeyper
Copy link
Member

mpeyper commented Mar 31, 2019

Thanks. I've added an item to #19 for wrapper documentation. I'll close this one now and any PR can be made against that.

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

No branches or pull requests

2 participants