mirror of
https://github.com/facebook/react.git
synced 2026-02-24 20:53:03 +00:00
35 lines
621 B
JavaScript
35 lines
621 B
JavaScript
// @flow
|
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
function wrapWithHoc(Component, index) {
|
|
function HOC() {
|
|
return <Component />;
|
|
}
|
|
HOC.displayName = `HOC-${index}`;
|
|
return HOC;
|
|
}
|
|
|
|
function wrapWithNested(Component, times) {
|
|
for (let i = 0; i < times; i++) {
|
|
Component = wrapWithHoc(Component, i);
|
|
}
|
|
|
|
return Component;
|
|
}
|
|
|
|
function Nested() {
|
|
return <div>Deeply nested div</div>;
|
|
}
|
|
|
|
const DeeplyNested = wrapWithNested(Nested, 100);
|
|
|
|
export default function DeeplyNestedComponents() {
|
|
return (
|
|
<Fragment>
|
|
<h1>Deeply nested component</h1>
|
|
<DeeplyNested />
|
|
</Fragment>
|
|
);
|
|
}
|