-
-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] [Table] Support pass custom porps to wrapper component #32922
Comments
What property you need to add on |
It's about business logic, like I need to do some effects in the |
I believe there is another way to implement this logic instead of adding extra props. |
是有,不过很麻烦。。比如可以通过 Context 来做:
不过这样太麻烦了。。。从逻辑上来讲,如果提供了方式允许开发者自定义 wrapper,其本意应该就是让开发者可以自己控制给 tr,td,tbody 外层再套一层,但是现在套的这一层又不能传任何 props,而且 从需求上来讲,套一层的目的肯定是根据某个条件或者在某些情况下做一些定制化的东西呀,这个条件肯定是大概率从 props 来的,但是现在又不能传过去,哭泣 |
function Foo(props) {
console.log(props.customProp); // 'customProp'
return ....
}
- components={{ body: { wrapper: Foo } }}
+ components={{ body: { wrapper: (props) => <Foo {...props} customProp="customProp" /> } }} 是不是这样就能传递你想传的任何自定义属性了? |
不行。。 和 #32897 类似,这里 inline 的那个箭头函数组件每次 render 的时候都会被卸载 我理解之所以有 onRow 这个 prop,原因之一其实就是为了避免 components.body.row 出现上面的问题,看来之前并不是为了这个 😂 一般的库很少遇到这种问题,因为他们大多是透传 props 给 wrappr,如果透传太麻烦或者有风险(比如 table 这样 props 本来就非常多复杂的),一般会选择一个单独的字段用那个字段透传,比如 antd table 的 onRow,或者叫 getWrapperProps 也行。 还有一种方式是不是接收一个 wrapper 了,而是直接提供一个 wrapper 组件或者写明声明一个 name 叫 xxx 的就当他是 wrapper,然后直接写 jsx element(当然自己不能有 children,而且要负责透传 children) 当作 children 传给库直接用 |
@afc163 肿么样 |
这个可以用 React.memo 或 React.useCallback 进行优化的。 |
@afc163 也不行的😂,因为现在有 bug,用了 React.memo 也一样会无限被卸载,原因在 #32897 (comment) 里解释啦 |
@afc163 进行一个 friendly 的 ping #32922 (comment) |
What problem does this feature solve?
Currently the
components.body.wrapper
component can't recevie any prop, butcomponents.body.row
can by theonRow
prop.What does the proposed API look like?
I would suggest support a new prop like
onContainer
oronWrapper
, and then the logic is same asonRow
.The text was updated successfully, but these errors were encountered: