Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “正在通过”;道具;道具对象之外的反模式?_Javascript_Reactjs_Design Patterns_Functional Programming - Fatal编程技术网

Javascript “正在通过”;道具;道具对象之外的反模式?

Javascript “正在通过”;道具;道具对象之外的反模式?,javascript,reactjs,design-patterns,functional-programming,Javascript,Reactjs,Design Patterns,Functional Programming,我正在使用AntD组件。当我生成列时,我希望将自定义道具传递给我的单元格,而这些单元格不属于我输入表的数据的一部分。可以是主题、调色板、布局设置等 每一列都由一个对象表示,并有一个render方法。AntD迭代行和列,并传递该行的记录,以由给定的单元格呈现 { ... // keys like `key`, `title`, `dataIndex` ... render: (record) => {...} } 而不是像这样直接将额外的道具传递给组件本身: { ...

我正在使用
AntD
组件。当我生成列时,我希望将自定义道具传递给我的单元格,而这些单元格不属于我输入表的数据的一部分。可以是主题、调色板、布局设置等

每一列都由一个对象表示,并有一个
render
方法。AntD迭代行和列,并传递该行的
记录
,以由给定的
单元格
呈现

{
   ... // keys like `key`, `title`, `dataIndex` ...
   render: (record) => {...}
}
而不是像这样直接将额外的道具传递给组件本身:

{
   ... // keys like `key`, `title`, `dataIndex` ...
   render: (record) => <MyCell {...record} extraProp={extraProp} extraProp2={extraProp2} />
}
{
   ... // keys like `key`, `title`, `dataIndex` ...
   render: MyCell(extraProp, extraProp2)
}
其中,迈塞尔的定义为:

const MyCell = (extrProp, extraProp2) => props => {...}
我应该坚持使用常规道具吗?或者,如果我像这样把多余的道具传给别人可以吗

它会导致糟糕的性能吗?将来它会咬我,让我很难追踪虫子吗


谢谢

两种方法略有不同

// It isn't a functional component, 
// it's curried function which returns a functional component
const generateMyCell = (extrProp, extraProp2) => props => {...}

//   ^ naming it MyCell is misleading.
主要区别在于,额外的道具(
extraProp-x
)在使用功能时是动态的,在使用功能组件时是静态的:

//                     v The extra props are static, they won't change
render: record => (
  <MyCell {...record} extraProp={extraProp} extraProp2={extraProp2} />
);

//         v The developer shows intetation that props may change
render: generateMyCell(extraProp, extraProp2)

两种方法略有不同

// It isn't a functional component, 
// it's curried function which returns a functional component
const generateMyCell = (extrProp, extraProp2) => props => {...}

//   ^ naming it MyCell is misleading.
主要区别在于,额外的道具(
extraProp-x
)在使用功能时是动态的,在使用功能组件时是静态的:

//                     v The extra props are static, they won't change
render: record => (
  <MyCell {...record} extraProp={extraProp} extraProp2={extraProp2} />
);

//         v The developer shows intetation that props may change
render: generateMyCell(extraProp, extraProp2)