Skip to content

Instantly share code, notes, and snippets.

View gragland's full-sized avatar

Gabe Ragland gragland

View GitHub Profile
@gragland
gragland / Stylefile.yml
Created July 31, 2018 15:27
Customizations for www.producthunt.com via StyleURL.
---
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
import { useState } from 'react';
// Usage
function App() {
const [name, setName] = useLocalStorage('name', '');
return (
<div>
<input
type="text"
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
import { useRef, useState, useEffect } from 'react';
// Usage
function App() {
const [hoverRef, isHovered] = useHover();
return (
<div ref={hoverRef}>
{isHovered ? '😁' : '☹️'}
</div>
import { useState, useEffect } from 'react';
// Usage
function App() {
const size = useWindowSize();
return (
<div>
{size.width}px / {size.height}px
</div>
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 (
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));
import { useState, useEffect, useRef } from 'react';
// Usage
function App() {
// State value and setter for our example
const [count, setCount] = useState(0);
// Get the previous value (was passed into hook on last render)
const prevCount = usePrevious(count);
import { useState, useEffect, useRef } from 'react';
// Usage
function App() {
// Ref for the element that we want to detect whether on screen
const ref = useRef();
// Call the hook passing in ref and root margin
// In this case it would only be considered onScreen if more ...
// ... than 300px of element is visible.
const onScreen = useOnScreen(ref, '-300px');
import { useState, useEffect, useRef } from 'react';
// Usage
function App() {
// State and setters for ...
// Search term
const [searchTerm, setSearchTerm] = useState('');
// API search results
const [results, setResults] = useState([]);
// Searching status (whether there is pending API request)