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
How does react know that a stateless function is a react component #18
Comments
Actually, as I typed it I realized that this wouldn't be react it would be babel that would do the work. I will look into it to see how they do it. |
@DianaSuvorova , I don't think it's a babel. Support of stateless functional components was added in some of the old versions, but it hadn't been like that from the very beginning. What do you actually mean by 'how does React know'? It doesn't :) I mean, it's not a React component till it's not pasted into other component's render method or ReactDOM.render. Then a ReactElement configuration object will be created for it and after a ReactCompositeComponent object will be instantiated from that configuration object. Here is how it works:
{
$$typeof: Symbol(react.element),
key: null,
props: {props...},
ref: null,
type: ƒ statelessComponent(props),
...
}
So, the thing is React allows you to pass into |
That explains it! So react only knows it during runtime. I was looking for a static analysis method. But this makes sense! Thank you! |
Thank you! |
First of all thanks for publishing this. This looks like an enormous effort that would benefit a lot of people.
I am working on a few issues for https://github.com/yannickcr/eslint-plugin-react library and have very specific question that you might have an answer for.
How does react know that a stateless function is a react component.
For example:
If you could point to a source code where react evaluate whether a function is a React or not that would be awesome. Any other directions would also be greatly appreciated
Thanks,
Diana
The text was updated successfully, but these errors were encountered: