Skip to content

Instantly share code, notes, and snippets.

View rsturim's full-sized avatar

Rich Sturim rsturim

  • VT, USA
View GitHub Profile
function App() {
const handleScroll = useCallback(() => {
console.log(window.scrollY);
}, []);
useEffect(() => {
// subscribe to scroll event
window.addEventListener('scroll', handleScroll);
return () => {
import React, { useState } from "react";
export default function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<h1>Count is {count}</h1>
<button
import { useMemo, useState, useEffect } from "react";
import { debounce } from "lodash";
export default function Input() {
const [query, setQuery] = useState("");
const changeHandler = (event) => {
setQuery(event.target.value);
};
const debouncedChangeHandler = useMemo(
@rsturim
rsturim / .eslintrc.js
Created December 6, 2020 14:47
Primo Eslint config — .eslintrc.js
'use strict';
module.exports = {
env: {
es6: true,
},
rules: {
strict: ['error', 'global'],
'func-style': ['error', 'expression'],
'no-new-func': 'error',
@rsturim
rsturim / useFetch.js
Last active July 2, 2020 11:00
custom hook for fetch
const useFetch = endpoint => {
const defaultHeader = {
Accept: "application/json",
"Content-Type": "application/json"
};
const customFetch = (
url,
method = "GET",
body = false,
headers = defaultHeader
import { useState } from 'react'
const useForm = initialValues => {
const [values, setValues] = useState({
...initialValues,
isSubmitting: false,
})
const handleSubmit = (event, callback) => {
if (event) {
@rsturim
rsturim / dabblet.css
Created September 27, 2013 07:46 — forked from anonymous/dabblet.css
This is the "Checkbox Hack".
/* Checkbox Hack */
input[type=checkbox] {
position: absolute;
top: -9999px;
left: -9999px;
}
label {
/* -webkit-appearance: push-button;
@rsturim
rsturim / ExtendNamespace
Created February 25, 2013 21:55
Automating nested namespacing. Credited to Addy Osmani, based on a pattern by Stoyan Stefanov. http://goo.gl/T8Vqk
// Convenience function for parsing string namespaces and
// automatically generating nested namespaces
function extendNamespace( ns, ns_string ) {
var parts = ns_string.split("."),
parent = ns,
pl;
pl = parts.length;
for ( var i = 0; i < pl; i++ ) {