Skip to content

Documentation for stateless functions/components, condensed two pages about refs into one #4964

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

Merged
merged 1 commit into from
Oct 1, 2015

Conversation

jimfb
Copy link
Contributor

@jimfb jimfb commented Sep 24, 2015

Condensed the two refs pages into a single refs page, added a note about stateless components having null references.

@jimfb
Copy link
Contributor Author

jimfb commented Sep 24, 2015

@zpao @spicyj Fixes #4913

@jimfb jimfb force-pushed the stateless-functions-and-render-docs branch from f28ac0f to 0295ff6 Compare September 24, 2015 18:20
@jimfb jimfb force-pushed the stateless-functions-and-render-docs branch from 0295ff6 to 1a53e82 Compare September 24, 2015 20:59
@jimfb
Copy link
Contributor Author

jimfb commented Sep 24, 2015

Added documentation for stateless components, as per conversation with @spicyj.

@jimfb jimfb force-pushed the stateless-functions-and-render-docs branch from 1a53e82 to 133ff81 Compare September 24, 2015 21:02
@jimfb jimfb added this to the 0.14 milestone Sep 24, 2015
@jimfb jimfb changed the title Condensed the two refs pages into a single refs page, added a note about stateless components having Documentation for stateless functions/components, condensed two pages about refs into one Sep 24, 2015
@@ -1,13 +1,97 @@
---
id: more-about-refs
title: More About Refs
title: References to Components
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we call it "Refs to Components" here (and in the sidebar, if that's specified somewhere else)?

@jimfb jimfb force-pushed the stateless-functions-and-render-docs branch 3 times, most recently from 80eab35 to 1c1e7b4 Compare September 29, 2015 01:08
@jimfb
Copy link
Contributor Author

jimfb commented Sep 29, 2015

@spicyj Fixed, ready to go?

@jimfb jimfb force-pushed the stateless-functions-and-render-docs branch from 1c1e7b4 to e3821e7 Compare September 29, 2015 01:14
}
}} />
<div>
<input type="text" ref="(ref) => this.myTextInput = ref" />
Copy link

Choose a reason for hiding this comment

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

Shouldn't this be ref={(ref) => this.myTextInput = ref} ??

Copy link
Member

Choose a reason for hiding this comment

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

Yes

Copy link
Member

Choose a reason for hiding this comment

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

Actually this should just be ref="myTextInput" since we're talking about string refs.

@zpao zpao mentioned this pull request Sep 30, 2015
17 tasks

> NOTE:
>
> Because stateless functions don't have a backing instance, you can't attach a ref to a stateless function component. Normally this isn't an issue, since stateless functions do not provide an imperative API, there really isn't much you could do with an instance anyway. However, if a user wants to find the DOM node of a stateless function component, they must wrap the component in a stateful component (eg. ES6 class component) and attach the ref to the stateful wrapper component.
Copy link
Member

Choose a reason for hiding this comment

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

Normally this isn't an issue, since stateless functions do not provide an imperative API, there really isn't much you could do with an instance anyway.

This doesn't parse as a sentence to me. Maybe split into 2 sentences at the first comma?

```


This simplified component API is intended for components that are pure functions of their props. These components must not retain internal state, do not have backing instances, and do not have the component lifecycle methods. They are pure functional transforms of their input, with zero boilerplate.
Copy link
Member

Choose a reason for hiding this comment

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

Super nit (that I shouldn't actually care much about but that tiny bit of OCD in my brain decided to notice): the rest of our docs uses a single space after periods in a sentence. You used 2 (and not entirely consistently at that). I'm sure you'll ignore this and that's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, one space for proportional fonts and two spaces for monospace fonts leaves it ambiguous what to do when you're writing .md which will turn into HTML. I went ahead and changed this file to single-space, though we aren't exactly consistent throughout the rest of our docs :).

@jimfb jimfb force-pushed the stateless-functions-and-render-docs branch from e3821e7 to f7000b9 Compare September 30, 2015 22:22
@jimfb
Copy link
Contributor Author

jimfb commented Sep 30, 2015

Good to go?

@jimfb jimfb force-pushed the stateless-functions-and-render-docs branch from f7000b9 to 10ea270 Compare September 30, 2015 22:25

So how do we talk to the *real* backing instance of the input?
Note that when the referenced component is unmounted and whenever the ref changes, the old ref will be called with `null` as an argument. This prevents memory leaks in the case that the instance is stored, as in the first example. Also note that when writing refs with inline function expressions as in the examples here, React sees a different function object each time so on every update, ref will be called with `null` immediately before it's called with the component instance.
Copy link
Member

Choose a reason for hiding this comment

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

nit: leading whitespace is still here (and in the next paragraph, and the one after that… and the one after that but you didn't add that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@jimfb jimfb force-pushed the stateless-functions-and-render-docs branch from 10ea270 to 5ee8a93 Compare October 1, 2015 01:54
@zpao
Copy link
Member

zpao commented Oct 1, 2015

👍

jimfb added a commit that referenced this pull request Oct 1, 2015
Documentation for stateless functions/components, condensed two pages about refs into one
@jimfb jimfb merged commit 6dbdea1 into facebook:master Oct 1, 2015
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.

9 participants