import { useCascader } from "@taroify/hooks"
import area from "./area"
const [value, setValue] = useState<string[]>([])
const { columns } = useCascader({ value, depth: 3, options: area })
console.log(columns); // -> options[]
// area
export default [
{
label: "浙江省",
value: "330000",
children: [
{
label: "杭州市",
value: "330100",
children: [
{
label: "上城区",
value: "330102",
},
{
label: "下城区",
value: "330103",
},
{
label: "江干区",
value: "330104",
},
],
},
{
label: "宁波市",
value: "330200",
children: [
{
label: "海曙区",
value: "330203",
},
{
label: "江北区",
value: "330205",
},
{
label: "北仑区",
value: "330206",
},
],
},
{
label: "温州市",
value: "330300",
children: [
{
label: "鹿城区",
value: "330302",
},
{
label: "龙湾区",
value: "330303",
},
{
label: "瓯海区",
value: "330304",
},
],
},
],
},
]
interface CascaderColumn {
value?: any
label?: ReactNode
disabled?: boolean
}
interface CascaderOption extends CascaderColumn {
children?: CascaderOption[]
}
interface UseCascaderOptions {
value?: any[]
depth?: number
options: CascaderOption[]
}
interface CascaderObject {
columns: CascaderOption[][]
}
function useCascader(options: UseCascaderOptions): CascaderObject