Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

custom hook for unique items in react

// 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];
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to generate an onclose jest 
Javascript :: cy wait for xhr 
Javascript :: how to get the number of days in a month in javascript 
Javascript :: Comparing traditional functions to arrow functions 
Javascript :: react get dynamic window sizes 
Javascript :: json to schema javascript 
Javascript :: jqiery bpopup append 
Javascript :: the caller does not have permission firestore 
Javascript :: javascript source code for digital meter 
Javascript :: convert space to dash/hyphen javascript regex 
Javascript :: how to make gamemaker games in javascript 
Javascript :: why is javascript the worst programming language 
Javascript :: convert to arrow functions 
Javascript :: cancellable function 
Javascript :: createPortal usage 
Javascript :: react auto import sometime not working 
Javascript :: xslt 2 node text replace string 
Javascript :: node js validate body without middleware 
Javascript :: the type of one of the join expressions is incorrect 
Javascript :: indonesia whatsapp formatter javascript 
Javascript :: react google login button size increase 
Javascript :: convert number to words javascript lakh 
Javascript :: add button to add item javascript 
Javascript :: Detect when the BACKSPACE is pressed 
Javascript :: cannot find module react scripts 
Javascript :: js to jquery converter online 
Javascript :: signed url to get file from s3 bucket 
Javascript :: how to connect terminal with javascript 
Javascript :: go back to screen with params react native 
Javascript :: js check if field in database is true or false 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =