Skip to content

Adjust how arguments to rendered hooks are provided #407

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
cincospenguinos opened this issue Jul 15, 2020 · 1 comment
Closed

Adjust how arguments to rendered hooks are provided #407

cincospenguinos opened this issue Jul 15, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@cincospenguinos
Copy link

cincospenguinos commented Jul 15, 2020

Describe the feature you'd like:

I find usage of this library hard to grok. If I understand correctly, the current interface for rendering and rerendering a hook is something to this effect:

const { rerender } = renderHook((props) => useMyHook(props.arg1, props.arg2), { initialProps: { arg1: 'foo', arg2: 'bar' } });
rerender({ arg1: 'bar', arg2: 'foo' });

A downside to this is that as arguments grow, so too does the initial props object grow too.

Suggested implementation:

Another way to interact with rendering a hook would simply be switching over to an array of arguments. This would
allow handing the hook to render directly rather than providing an anonymous function:

const { rerender } = renderHook(useMyHook, ['foo', 'bar']);
rerender(['bar', 'foo']);

Describe alternatives you've considered:

I have no real alternatives--I just found myself struggling to get renderHook to work simply because I found the usage API to be unintuitive. I think my proposed solution would simplify interaction with the library, as hooks will always be functions and you will always provide arguments to a function, making an array a more expressive representation of function arguments than a javascript object.

Teachability, Documentation, Adoption, Migration Strategy:

NOTE

I would be more than happy to implement this change to the API, given the fact that what I'm asking for is a decent amount of work.

@cincospenguinos cincospenguinos added the enhancement New feature or request label Jul 15, 2020
@mpeyper
Copy link
Member

mpeyper commented Jul 16, 2020

Hi @cincospenguinos,

I've addressed similar suggestions in #56 previously. I'll close this and move the suggestion over there to keep it all together and address talk to the idea there as well.

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

No branches or pull requests

2 participants