Skip to content

Instantly share code, notes, and snippets.

View codemzy's full-sized avatar

Codemzy codemzy

View GitHub Profile
@codemzy
codemzy / uk-cities-towns-populations.json
Created April 18, 2018 09:22
UK Cities and Towns Populations 2017
[
{
"location": "Abberton",
"population": "831"
},
{
"location": "Abbeytown",
"population": "819"
},
{
@codemzy
codemzy / react.context.multipleConsumers.js
Created April 4, 2019 13:27
Function including hoc to add consume multiple contexts in a component
import React from 'react';
// consumers
import { AlertConsumer } from './Alert'; // AlertContext.Consumer
import { UserConsumer } from './User'; //UserContext.Consumer
// -------------- CONTEXT FUNCTIONS -------------- //
// hoc for adding a context to a component as a consumer
const hocContextConsumer = function(ComposedComponent, ContextConsumer, name) {
@codemzy
codemzy / useDelay.js
Created February 25, 2021 11:03
React useDelay hook - to avoid flash of loading content
import React from "react";
// delay a state change (used for loading or waiting for async to avoid flash of loading state)
export default function useDelay(initial, { delay = 300, delayedValue = true, minDuration = 700 }) {
const [state, setState] = React.useState(initial);
const [change, setChange] = React.useState(initial);
const end = React.useRef(0);
React.useEffect(() => {
let timer;
@codemzy
codemzy / Drag.js
Last active March 22, 2024 11:39
React Drag-and-Drop Component
import React from 'react';
// sub-components
import DragItem from './DragItem';
import DropZone from './DropZone';
import DropZones from './DropZones';
import DropGuide from './DropGuide';
// context for the drag
export const DragContext = React.createContext();