Skip to content
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

ReactDOM.render returns null for pure functions #5455

Closed
jamiebuilds opened this issue Nov 12, 2015 · 1 comment
Closed

ReactDOM.render returns null for pure functions #5455

jamiebuilds opened this issue Nov 12, 2015 · 1 comment

Comments

@jamiebuilds
Copy link

I was thrown off by this behavior, figured it warranted an issue.

function Component() {
  return <div/>;
}

var result = ReactDOM.render(<Component/>, el);

result === null;

I was attempting to ReactDOM.findDOMNode the result of ReactDOM.render.

@jimfb
Copy link
Contributor

jimfb commented Nov 12, 2015

Documented in several places:

Render a ReactElement into the DOM in the supplied container and return a reference to the component (or returns null for stateless components).

As well as mentioned in big red boxes:

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. Without an imperative API, there 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.

Duplicate of #4936

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

2 participants