Skip to content

Conversation

@bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Mar 14, 2018

Based on team discussion about awkwardness of inputRef.value.value.

Docs have been updated as well, via 12d7c16.

@trueadm
Copy link
Contributor

trueadm commented Mar 14, 2018

Did we want to also ensure that the ref object is valid by checking if it has the current property inside it? This relates to something @sophiebits mentioned the other day.

Copy link
Contributor

@trueadm trueadm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check for current, otherwise awesome!

@bvaughn
Copy link
Contributor Author

bvaughn commented Mar 14, 2018

Sounds like you're advocating some new functionality? Inside of commitAttachRef?

@gaearon
Copy link
Collaborator

gaearon commented Mar 14, 2018

Yes, we should warn here if the object doesn't have an own current property. Because it means they probably passed something else accidentally.

@gaearon
Copy link
Collaborator

gaearon commented Mar 14, 2018

(This probably doesn't block the alpha but we need to add it to final release checklist. It should be a three line change though.)

@bvaughn
Copy link
Contributor Author

bvaughn commented Mar 14, 2018

Sure, sure. I just wanted to clarify what was being suggested 👍

@bvaughn
Copy link
Contributor Author

bvaughn commented Mar 14, 2018

Okay. Added a DEV warning for this, plus a test.

@bvaughn bvaughn merged commit 7719610 into facebook:master Mar 14, 2018
@bvaughn bvaughn deleted the createRef-update branch March 14, 2018 16:43
@alexkrolick
Copy link

Docs note:
I made the new callback ref example use an object instead of the usual direct reference so that it would have the same access API as createRef.

ref={el => this.someRef.current = el}
ref={this.someRef = el}

Idk if that is too much indirection. It could def cause some "could not access property 'current' of undefined" issues if not initialized.

reactjs/react.dev@12d7c16#diff-5ff76597e6c547982df2b2e42f2f83c0R279

@bvaughn
Copy link
Contributor Author

bvaughn commented Mar 14, 2018

I don't see much value in showing an object wrapper for the callback ref example:

this.textInput = { current: null }; // initial placeholder for the ref

My vote for the callback example would just be to write to this.textInput directly.

alexkrolick added a commit to bvaughn/reactjs.org that referenced this pull request Mar 15, 2018
LeonYuAng3NT pushed a commit to LeonYuAng3NT/react that referenced this pull request Mar 22, 2018
* Renamed createRef .value attribute to .current

* Warn if invalid ref object is passed
rhagigi pushed a commit to rhagigi/react that referenced this pull request Apr 19, 2018
* Renamed createRef .value attribute to .current

* Warn if invalid ref object is passed
OhIAmFine pushed a commit to OhIAmFine/zh-hans.reactjs.org that referenced this pull request May 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants