【Feat】useAntdTable-options-defaultParams ,是否考虑新增params 以支持在Service函数中能够始终获得最新的默认参数
- Dominant language
- TypeScript
- Stars
- 15k
- Forks
- 2.8k
- Avg merge
- 15h 7m
- Merged PRs (30d)
- 2
Description
```tsx
const [id , setId] = useState(1)
const { tableProps, search } = useAntdTable((...rest)=>{
console.log(rest.id) // 这里无论 id 变化,都无法获取到最新的,始终得到 1
}, {
form,
manual: true,
debounceTrailing: true,
debounceWait: 300,
defaultPageSize: 10,
defaultParams: [{ id } as any],
params:[{ ... }] // 【Feat】既然defaultParams 仅作为第一次默认值使用,那么是否可以再支持一个具有副作用的参数列表
})
```
为什么?
1. 都无法获取到最新的,始终得到 1
```tsx
const Component = () => {
const [id , setId] = useState(1)
const getTable = (...rest)=>{
console.log(rest.id) // 这里无论 id 变化,都无法获取到最新的,始终得到 1
console.log(id) // 可以拿到,但是 getTable 就和组件耦合了
}
const { tableProps, search } = useAntdTable(getTable, {
form,
defaultParams: [{ id } as any],
})
}
```
2. 无法通过 submit 传递参数
```tsx
search: {
type: 'simple' | 'advance';
changeType: () => void;
submit: () => void; //这里无法透传
reset: () => void;
}
```
那么如果我用 run 或者 runAsync 透传参数就更麻烦了。因为 TParams 类型复杂,我直接使用 run(...useAntdTable().params) ,ts通过性不好,其次 TParams[0]. xxx 仍然是 defaultParams里的旧值,还是需要手动修改
3. 为什么不通过 form 来设置默认值
使用 useAntdTable 配合 form ,一般很少再自己做校验了,否则就失去了直接 submit 而不需要传入参数的意义了。
我如果自己先调用form相关方法再设置默认值,那么参数处理的又耦合回组件内部,而不是统一在 Service 里处理
Contributor guide
Research direction
Start by reading the useAntdTable entry point and its defaultParams, search.submit, run, and runAsync interfaces. Trace how parameters reach the Service function and determine how a new reactive parameter list would interact with form submission and existing TypeScript types. Done means the requested parameters consistently expose current values without requiring component-specific coupling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100