如何在Reaction中呈现递归组件?

e4yzc0pl  于 2022-10-15  发布在  React
关注(0)|答案(0)|浏览(135)

我正在尝试递归呈现组件。在每次递归调用时,我从维度中减去10px。我预计会有一系列嵌套的div,每个div都要小10px。当高度和宽度达到10px时,组件应该返回空,这就是我的基本情况。
除了预期的结果,我什么都没有得到。终端中没有错误,开发工具中也没有错误,只是页面被冻结了。
有什么想法吗?

RecurentDiv.js

const RecurentDiv = ({ width, height }) => {
  const style = {
    width: `${width - 10}px`,
    height: `${height - 10}px`,
    border: "1px solid black",
    display: "inline-block"
  };

  if (width < 10) return null; //base case

  return (
      <div style={style}>
        <RecurentDiv width={style.width} height={style.height} />
      </div>
  );
};

export default RecurentDiv;

App.js

<RecurentDiv width={100} height={100} />

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题