function createQueryString(obj) {
const query = new URLSearchParams()
for (const key in obj) {
if (Object.hasOwn(obj, key)) {
const item = obj[key]
if (!Array.isArray(item))
query.append(key, String(item))
else {
for (const el of item) {
query.append(key, String(el))
}
}
}
}
return query.toString()
}
const args = {
hi: 'there',
id: ['1', '2', '3']
}
console.log(createQueryString(args))
const defObj = {
a: { label: string, value: number },
b: { label: string, value: string },
c: { label: string, value: boolean }
}
type Generic =
| { label: string, value: number }
| { label: string, value: string}
| { label: string, value: boolean}
type Test = Record<string, Generic>
setData((prev) => prev.map((it, i) => {
return index !== i ? it : {
...it, [key]: value
}
}))