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
| function App() { | |
| const handleScroll = useCallback(() => { | |
| console.log(window.scrollY); | |
| }, []); | |
| useEffect(() => { | |
| // subscribe to scroll event | |
| window.addEventListener('scroll', handleScroll); | |
| 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 React, { useState } from "react"; | |
| export default function Counter() { | |
| const [count, setCount] = useState(0); | |
| return ( | |
| <div> | |
| <h1>Count is {count}</h1> | |
| <button |
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 { 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( |
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
| 'use strict'; | |
| module.exports = { | |
| env: { | |
| es6: true, | |
| }, | |
| rules: { | |
| strict: ['error', 'global'], | |
| 'func-style': ['error', 'expression'], | |
| 'no-new-func': 'error', |
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
| const useFetch = endpoint => { | |
| const defaultHeader = { | |
| Accept: "application/json", | |
| "Content-Type": "application/json" | |
| }; | |
| const customFetch = ( | |
| url, | |
| method = "GET", | |
| body = false, | |
| headers = defaultHeader |
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' | |
| const useForm = initialValues => { | |
| const [values, setValues] = useState({ | |
| ...initialValues, | |
| isSubmitting: false, | |
| }) | |
| const handleSubmit = (event, callback) => { | |
| if (event) { |
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
| /* Checkbox Hack */ | |
| input[type=checkbox] { | |
| position: absolute; | |
| top: -9999px; | |
| left: -9999px; | |
| } | |
| label { | |
| /* -webkit-appearance: push-button; |
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
| // 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++ ) { |