反应递归嵌套组件

问题描述

import { render } from "react";

const MyComponent = ({ count = 0,children }) => {
  return count === 1 ? null : (
    <div style={{ border: "3px solid #ccc",margin: 5 }}>
      {children}
      <MyComponent count={++count} children={children} />
    </div>
  );
};

const App = () => {
  return (
    <div>
      <MyComponent>
        hi
        <MyComponent>
          wow
          <MyComponent> bye </MyComponent>
          <MyComponent> bye </MyComponent>
          <MyComponent> bye </MyComponent>
        </MyComponent>
      </MyComponent>
    </div>
  );
};

render(<App />,document.getElementById("root"));

如何在没有count props的情况下解决上面的代码。我想做上面的嵌套组件。谁能指导我如何实现这一目标?

代码https://codesandbox.io/s/preact-nested-recursive-vjrle

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)