📅  最后修改于: 2022-03-11 15:03:58.243000             🧑  作者: Mango
// useUnique.js
export function useUnique(initial) {
const [items, setItems] = useState(initial);
const add = newItem => {
const uniqueItems = [...new Set([...items, newItem])];
setItems(uniqueItems);
};
return [items, add];
};