stackjlei stackjlei - 4 years ago 88
React JSX Question

How are React component instances different than other frame works?

In the docs, React says that it doesn't really care for instances as the Components take props as input and outputs elements for you. It gives you an example at the top of how other frameworks have to create an instance and then connect it to the DOM to handle different events. But I don't understand how this is different than what React is doing.

You're not calling

on your component in React, but you still have to render it and create all the same handlers. And
inside the component still refers to the instance, so doesn't React still have to create an instance each time your component is rendered (even if it's a component inside an
that's being rendered several times at once).

Traditional frameworks will have to create multiple instances of the same component to connect to each DOM node it corresponds to, isn't that what React is doing too? How else can one component keep track of multiple

Answer Source

Indeed, React creates Component instance internally. You don't need to worry about using new.

React Element is just a plain JavaScript Object that describes what you want to be rendered (React.Component or HTML Element, if type is a String).

From the docs:

An element is not an actual instance. Rather, it is a way to tell React what you want to see on the screen. You can’t call any methods on the element. It’s just an immutable description object with two fields: type: (string | ReactClass) and props: Object1.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download