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

Make the ref hook a proper ref #57

Merged
merged 2 commits into from
Nov 19, 2019
Merged

Make the ref hook a proper ref #57

merged 2 commits into from
Nov 19, 2019

Conversation

glennsl
Copy link
Collaborator

@glennsl glennsl commented Nov 19, 2019

This has the ref hook return an actual ref, removes the setter, and therefore acts, and has to be used, like an ordinary ref that persists across calls.

let%hook count = Hooks.ref(0);
count := count^ + 1; // Instead of `setCount(count + 1)`

The rationale for this change is that the name ref implies that the value 1) will be updated immediately, and 2) is a reference that will change its contents when updated elsewhere. Neither of which is true. It therefore acts like a bit of a trap which some people (i.e. me) fall into multiple times despite knowing how it actually works. An example is in revery-ui/revery#648. This change makes both of these implications true, while still fulfilling the role of the current ref hook, but at the cost of using a slightly different API than both React and the state hook.

@wokalski wokalski merged commit 0c63038 into briskml:master Nov 19, 2019
@wokalski
Copy link
Member

Thank you @glennsl. It's a very welcome addition.

@glennsl
Copy link
Collaborator Author

glennsl commented Nov 19, 2019

Thank you for the very quick acceptance and response!

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

Successfully merging this pull request may close these issues.

2 participants