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

Deprecate isValidClass #2374

Closed
sebmarkbage opened this issue Oct 18, 2014 · 3 comments · Fixed by #2384
Closed

Deprecate isValidClass #2374

sebmarkbage opened this issue Oct 18, 2014 · 3 comments · Fixed by #2384
Milestone

Comments

@sebmarkbage
Copy link
Collaborator

We should deprecate isValidClass. In 0.13, any function that returns an object with a render method will be a valid class.

We probably don't want to assume that there is a valid prototype because that doesn't allow the module pattern to be used:

function MyComponent(props) {
  return {
    render: function() {
      return <div />;
    }
  };
}

It's really difficult to validate these without invoking them. This is where a static type system shines. For a dynamic check, isValidClass would turn into: typeof fn === 'function' which doesn't need its own function.

Generally, you'll want to validate something extra about the class anyway. E.g. will it have a getDOMNode method on it? Does it render into a table cell?

@sebmarkbage sebmarkbage added this to the 0.12 milestone Oct 18, 2014
@sebmarkbage sebmarkbage mentioned this issue Oct 18, 2014
11 tasks
@zpao
Copy link
Member

zpao commented Oct 19, 2014

So you know we put out an RC already, right? We really should have decided this before that happened. But sure, let's deprecate it. Want to put up that PR?

@sebmarkbage
Copy link
Collaborator Author

Thanks, Captain Hindsights

I didn't see it coming until I started working on it. We can also deprecate it in 0.13 but that'd change the semantics to just be === 'function'.

I'll put up a PR and we can decide later.

@lijunle
Copy link

lijunle commented Dec 1, 2014

Hi, sorry for comment on an old post.

I have a question on your assertion. You mentioned that:

any function that returns an object with a render method will be a valid class.

But, the function created by React.createClass will not return an object containing a render method. Actually, it is:

{ type: { [Function] displayName: 'Test' },
  key: null,
  ref: null,
  _owner: null,
  _context: {},
  _store: { validated: false, props: {} } }

So, basically, the current existing React Classes does not meet your criteria. :(

Any idea on this?


PS. Using React.createElement(class) does not return an object containing render function, too.

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

Successfully merging a pull request may close this issue.

3 participants