This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState, useEffect, useRef } from 'react'; | |
| // Usage | |
| function App() { | |
| // Create a ref that we add to the element for which we want to detect outside clicks | |
| const ref = useRef(); | |
| // State for our modal | |
| const [isModalOpen, setModalOpen] = useState(false); | |
| // Call hook passing in the ref and a function to call on outside click | |
| useOnClickOutside(ref, () => setModalOpen(false)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState, useEffect } from 'react'; | |
| // Usage | |
| function App() { | |
| // Call hook multiple times to get animated values with different start delays | |
| const animation1 = useAnimation('elastic', 600, 0); | |
| const animation2 = useAnimation('elastic', 600, 150); | |
| const animation3 = useAnimation('elastic', 600, 300); | |
| return ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState, useEffect } from 'react'; | |
| // Usage | |
| function App() { | |
| const size = useWindowSize(); | |
| return ( | |
| <div> | |
| {size.width}px / {size.height}px | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useRef, useState, useEffect } from 'react'; | |
| // Usage | |
| function App() { | |
| const [hoverRef, isHovered] = useHover(); | |
| return ( | |
| <div ref={hoverRef}> | |
| {isHovered ? '😁' : '☹️'} | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState } from 'react'; | |
| // Usage | |
| function App() { | |
| // Similar to useState but first arg is key to the value in local storage. | |
| const [name, setName] = useLocalStorage('name', 'Bob'); | |
| return ( | |
| <div> | |
| <input |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState } from 'react'; | |
| // Usage | |
| function App() { | |
| const [name, setName] = useLocalStorage('name', ''); | |
| return ( | |
| <div> | |
| <input | |
| type="text" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| version: 1.0 | |
| domains: | |
| - www.producthunt.com | |
| url_patterns: | |
| - www.producthunt.com/* | |
| timestamp: '2018-07-31T15:27:10Z' | |
| id: VSi0 | |
| redirect_url: https://www.producthunt.com/ | |
| shared_via: StyleURL - (https://styleurl.app) import and export CSS changes from Chrome |
NewerOlder