Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

createRef API like React 16.3 #70

Closed
LPGhatguy opened this issue Apr 20, 2018 · 3 comments
Closed

createRef API like React 16.3 #70

LPGhatguy opened this issue Apr 20, 2018 · 3 comments
Labels
feature: planned A feature that's been accepted into the project's roadmap.

Comments

@LPGhatguy
Copy link
Contributor

React 16.3+ exposes a new ref API that's intended to be the default instead of the callback refs that both React and Roact have.

I've found that a lot of users new to the React model try to do things like call setState inside refs, or do all sorts of trickery inside of them, when they really should be doing those things in didMount instead.

Switching the recommended API to a createRef-like API would prevent these issues in the future.

@LPGhatguy LPGhatguy added the feature: planned A feature that's been accepted into the project's roadmap. label Apr 20, 2018
@AmaranthineCodices
Copy link
Contributor

This would work way better than function-based refs. I am skeptical about one of the details of this:

When the ref attribute is used on a custom class component, the ref object receives the mounted instance of the component as its current.

This doesn't feel right. It's nice to completely encapsulate component behavior, and this breaks the encapsulation. With this functionality, I can write code that only works when a component is stateful, and mess with its internals arbitrarily. This is not ideal - it feels really imperative, as opposed to the general declarative nature of Roact and React.

@LPGhatguy
Copy link
Contributor Author

I didn't even notice that, that's pretty sketchy.

We can ignore that feature for now, and if we end up really (really really) wanting that, we can add it later.

@AmaranthineCodices
Copy link
Contributor

AmaranthineCodices commented May 15, 2018

I'm working on this locally; should have something tomorrow or Wednesday.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature: planned A feature that's been accepted into the project's roadmap.
Projects
None yet
Development

No branches or pull requests

2 participants