logo
Search
showing results for - "custom hook for unique items in react"
Lara
15 Jun 2020
1// useUnique.js
2export function useUnique(initial) {
3  const [items, setItems] = useState(initial);
4  const add = newItem => {
5    const uniqueItems = [...new Set([...items, newItem])];
6    setItems(uniqueItems);
7  };
8  return [items, add];
9};
source
similar questions
react custom hook to load data using apiupdate object in react hooksusefetch custom hook for reactreact custom hook refetch datareact hooks 2c react custom hooksreact update state hook with previous valuereact hook form password validation uppercaserendered more hooks than during the previous rendereplace componentwillmount with hookscustom hooks for password inputreact custom hooksreact hooks update parent state from childreact hooks inside class componentdeclaring variable react hooks
queries leading to this page
unique id hooks reactreact unique id hookcustom hook for unique items in reactcustom hook for unique items in react
privacy policyterms of useinstagram
Crafted with  ♥  for everyone

sign in to continue
your answer for
you will get a confirmation link on this - you will have to click that for successful submission of your answer. we require this to keep the website free of spam, bots and unhelpful content
please ensure to add code which is syntactically corrent and executes properly
sign in to continue
ask question on maxinterview
you will get a confirmation link on this - you will have to click that for successful submission of your question. we require this to keep the website free of spam, bots and unhelpful content
please be clear, to the point and respectful
sign in to continue