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

Support: `useRef(..)` hook #12

Closed
getify opened this Issue Jan 2, 2019 · 1 comment

Comments

Projects
None yet
1 participant
@getify
Copy link
Owner

getify commented Jan 2, 2019

This: https://reactjs.org/docs/hooks-reference.html#useref

And specifically: https://reactjs.org/docs/hooks-faq.html#is-there-something-like-instance-variables

One place we might deliberately diverge from React here is not to name the default property on the reference (object) as current. Since TNG doesn't have a ref JSX attribute, there's no magic population of some DOM element context. A better name for the property that better matches how this will likely be used in TNG is value I think.

So the initialValue passed in can just be added as .value to the reference (object).

We can just mention in the docs that you can add whatever other property(s) you want to this reference (object), including .current if preferred.

IIUC, I think useRef(..) can just be a super simple wrapper around useState(..):

function useRef(initialValue) {
   var [ref] = useState({ value: initialValue, });
   return ref;
}
@getify

This comment has been minimized.

Copy link
Owner

getify commented Jan 9, 2019

I've changed my mind, we'll keep to the current default property name as React does, rather than value. Consistency with React is ultimately more compelling than my preference for having a more relevant name for this property based on expected use cases with TNG.

@getify getify closed this in 7d01f0f Jan 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment