Skip to content

Instantly share code, notes, and snippets.

View Cool-Runningz's full-sized avatar

Alyssa Holland Cool-Runningz

View GitHub Profile
@Cool-Runningz
Cool-Runningz / useFetchAsync.js
Last active May 30, 2023 04:58
Async/await implementation of the useFetch hook
import { useEffect, useState } from "react";
const useFetchAsync = (initialUrl, options) => {
const [data, setData] = useState([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const [url, setUrl] = useState(initialUrl || "")
useEffect(() => {
if(!url) return
@Cool-Runningz
Cool-Runningz / useFetchReducer.js
Created August 2, 2022 01:34
Reducer implementation of the useFetch hook
import { useEffect, useState, useReducer } from "react";
const initialReducerState = {
data: [],
loading: false,
error: null
}
const ActionType = {
FETCH: 'FETCH_INIT',
import { useEffect, useState } from "react";
const useFetch = (initialUrl, options) => {
const [data, setData] = useState([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const [url, setUrl] = useState(initialUrl || "")
useEffect(() => {
if(!url) return
@Cool-Runningz
Cool-Runningz / useMediaQuery.ts
Created July 17, 2022 04:18
React hook that determines when a media query has been met
import { useEffect, useState } from "react";
function useMediaQuery(mediaQuery: string): boolean {
const [isMediaMatch, setIsMediaMatch] = useState(window.matchMedia(mediaQuery).matches);
useEffect(() => {
const mediaQueryList = window.matchMedia(mediaQuery);
const mqlHandler = () => setIsMediaMatch(mediaQueryList.matches);
mediaQueryList.addEventListener("change", mqlHandler);
@Cool-Runningz
Cool-Runningz / usaCities.js
Created February 6, 2022 01:48 — forked from Lwdthe1/usaCities.js
JSON of 5,950+ USA Cities and Their States
[
{'city': 'Abbeville', 'state': 'Louisiana'},
{'city': 'Aberdeen', 'state': 'Maryland'},
{'city': 'Aberdeen', 'state': 'Mississippi'},
{'city': 'Aberdeen', 'state': 'South Dakota'},
{'city': 'Aberdeen', 'state': 'Washington'},
{'city': 'Abilene', 'state': 'Texas'},
{'city': 'Abilene', 'state': 'Kansas'},
@Cool-Runningz
Cool-Runningz / vscode-snippets-js.json
Last active September 23, 2021 16:51
VSCode Snippets - JavaScript
{
"Console Log": {
"prefix": "cl",
"body": "console.log('$1')",
"description": "Inserts console.log('')"
},
"Inserts a noop": {
"prefix": "noop",
"body": ["() => {}"],
"description": "Inserts a noop"
@Cool-Runningz
Cool-Runningz / testing-jest-enzyme.md
Last active March 30, 2019 04:13
Article on installation, configuration and getting up and running with unit testing with Jest and Enzyme.

Unit Testing with Jest & Enzyme

This article was created to help you get up and running with Jest and Enzyme. It will cover installing and configuring Jest and Enzyme (not using Create React App). Basic unit test examples can be found in the source code.

Disclaimer

All the information provided has been compiled and adapted from the references cited at the end and throughtout the document. The guidelines are illustrated by either my own examples or samples found when researching this topic. A big thanks to all the authors who wrote the sources of information.