Skip to content

RFC: React forceRemount #3899

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
syranide opened this issue May 18, 2015 · 7 comments
Closed

RFC: React forceRemount #3899

syranide opened this issue May 18, 2015 · 7 comments

Comments

@syranide
Copy link
Contributor

We support uncontrolled components (although we do not necessarily encourage them) and it seems to me that this is a utility that is of relevance to a handful of such use-cases, especially in more complex situations. I.e. where you have a stateful component which you need to reset, say a rich-text editor or in my case of ReactSWF a running SWF, in response to some user action. EDIT: Think of it as a complement to React.findDOMNode(inputRef).value = 'foobar'.

This can currently be worked around by providing a monotonic key, but that's really just a hack and not a neat solution.

This is very much in the more obscure end of the spectrum but seems like a missing feature in-terms of being "feature complete" for uncontrolled components. So I'm not really going to push hard for this (especially as it could be really obscure and the above hack might really be the best trade-off, also considering batching).

@sophiebits
Copy link
Collaborator

Not sure what your proposed API is? Can you unmount and then remount?

@syranide syranide changed the title RFC: React.forceRemount RFC: React forceRemount May 19, 2015
@syranide
Copy link
Contributor Author

@spicyj Think thisOrRef.forceUpdate() but instead thisOrRef.forceRemount() I guess. So effectively forceUpdate() but rather than ignoring shouldComponentUpdate it will ignore and fail the internal shouldUpdateReactComponent instead, i.e. it will be unmounted and mounted just as if its key had changed.

@waldreiter
Copy link
Contributor

This would be a nice solution for some cases. But how would this work when everything gets rerendered from the top?

@syranide
Copy link
Contributor Author

@cody Just like forceUpdate (which is like setState + internal variable). So it's a regular, possibly batched, update like everything else but with an internal flag specifying that it must not pass the internal shouldUpdateReactComponent. (EDIT: So if the component ends up being unmounted by the parent then the flag will simply have no effect, so everything works out naturally)

React.addons.batchedUpdates is probably an important part in this for some of the use-cases and it's something I'd really like to see move out of addons, but that's another topic :)

@waldreiter
Copy link
Contributor

@syranide As I understand this, if everything gets rendered from the top, then this.forceRemount() needs to be called from componentWillReceiveProps. That would be not too bad. But I wonder if there are edge cases, since componentWillReceiveProps is only guaranteed to be called if props change?

React.addons.batchedUpdates is still undocumented, so I don't know what it does. (Issue is here: #3570)

@syranide
Copy link
Contributor Author

@cody Ah, yes I see what you mean now, that's a good point. I'm getting an uneasy feel thinking about all this now... hmm...

@sophiebits
Copy link
Collaborator

I don't think we'll do this since providing a new key is easy and we're trying to reduce API surface area, not increase it. Thanks for the idea.

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

No branches or pull requests

3 participants