Picker组件增强的一些想法,便于columns数据是异步获取的场景 #5399
damonyoungcc
started this conversation in
Ideas
Replies: 3 comments 14 replies
-
|
Beta Was this translation helpful? Give feedback.
1 reply
-
有一种边界情况需要考虑,如果用户初次点开 Picker,此时 |
Beta Was this translation helpful? Give feedback.
3 replies
-
基于上面我写了一点用法的伪代码 function BasicDemo() {
const [ visible, setVisible ] = useState(false);
const [ loading, setLoading ] = useState(false);
const [columns, setColumns] = useState([]);
const onOpen = async () => {
// 1、开启,2、columns长度为0,3、loading为false时请求
if(!columns.length && !loading) {
setLoading(true)
const data = await mockdata();
setColumns(data)
setLoading(false)
}
}
return (
<>
<Button
onClick={() => {
setVisible(true)
}}
>
选择
</Button>
<Picker
confirmDisabled={!loading}
placeholder={<div>loading...</div>} // 只有在传的情况下展示,不传保持原先样式不变
onOpen={onOpen}
columns={columns}
visible={visible}
onClose={() => {
setVisible(false)
}}
/>
</>
)
} |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
现在的问题:
源于这个
issue
: [Picker]组件增加loading属性,目前大部分用户异步获取columns数据的时机应该是两个:Picker
,传入columns
Picker
我想用户想要
loading
属性,大致是想在点击按钮后触发接口请求,而不是在一开始页面mount
时就加载过多数据。解决方案讨论
之前对于
antd
的Select
做过一些二次封装,利用了Select
组件的两个API
:notFoundContent
和onDropdownVisibleChange
,效果点这里思路就是:
Select
,先展示下拉框onDropdownVisibleChange
监听到open
为true
时发起异步请求,此时loading
状态置为为true
notFoundContent
传一个加载中的样式占位,等异步请求结束,则展示正常的内容。综上,是否可以给
Picker
组件增加notFoundContent
和onPopupVisibleChange
属性,这样用户在点击Picker
后,可以正常弹出Picker
,异步数据请求成功前,展示columns
的地方可以展示用户传入的骨架屏或loading组件,这样体验可能会更好。Beta Was this translation helpful? Give feedback.
All reactions