Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Example React Hook

const useCounter = (initialState = 0) => {
      const [count, setCount] = useState(initialState);
      const add = () => setCount(count + 1);
      const subtract = () => setCount(count - 1);
      return { count, add, subtract };
};
Source by www.smashingmagazine.com #
 
PREVIOUS NEXT
Tagged: #Example #React #Hook
ADD COMMENT
Topic
Name
8+7 =