Skip to content

Instantly share code, notes, and snippets.

@mlnor27
mlnor27 / useFetch.js
Last active November 23, 2022 09:32
"useFetch" - A little React hook to handle HTTP request
import { useEffect, useReducer, useRef } from "react";
const initialState = {
isLoading: false,
data: null,
err: null,
cancel: () => {}
};
const reducer = (state, { type, payload }) => {
@mlnor27
mlnor27 / Image.js
Last active May 3, 2019 16:17
A little lazyloaded image component using IntersectionObserver API
import React, { useEffect, useRef, useState } from "react";
import { string } from "prop-types";
const usePrevious = value => {
const ref = useRef();
useEffect(() => {
ref.current = value;
});
return ref.current;
};