gpt4 book ai didi

javascript - 在 React js 中传递多个 Prop 的最佳方法

转载 作者:行者123 更新时间:2023-12-05 00:28:07 25 4
gpt4 key购买 nike

传递图像中提到的 react Prop ,我想知道在 React 中传递多个 Prop 的任何更清洁的方法。
enter image description here

最佳答案

根据 react eslint 规则,出于可读性和维护原因,不建议使用 props 传播,阅读更多关于规则 here
因此,您可以做的是将其保持原样或将类似的 Prop 分组到一个对象中并传递它,例如:

const entity = { getEntity, entityKeyAccess, setEntityKeyAccess };
const display = { display, setDisplay };
const child = { childKeyAccess, setChildKeyAccess };
// And so on you get the idea I guess.

<PanelEntity panelData={panelData} entity={entity} display={display} child={child} />;
这样现在任何使用此组件的人都可以轻松理解您的 Prop (当然不要忘记记录您的 Prop ),并且您在不使用 Prop 传播的情况下整理了组件。

关于javascript - 在 React js 中传递多个 Prop 的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65931823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com