An basic Avatar
Component:
1 | class Avatar extends React.Component { |
And its functional component style is:
1 | const Avatar = ({ url }) => <img src={url} /> |
As you can see, it’s just a simple js function returning an element.
React still does a lot of stuff on functional components that, by nature, will never be used.
But we can skip React internals for these functional component.
They are just plain JavaScritp functions, which means we can call it in the render function.
1 | ReactDOM.render( |
As we know, the traditional usage:
1 | <Avatar url={avatarUrl} /> |
will be compiled into
1 | React.createElement(Avatar, { url: avatarUrl }) |
It will cost a lifecycle of a React Component.
But with direct calling of plain JavaScritp Function, all these consumption can be eliminated.
By the way, transform-react-inline-elements
does the same as a bebel transform, so there’s no need to change the source code.