Skip to content

Instantly share code, notes, and snippets.

View Stanley-Yao's full-sized avatar
🏠
Working from home

Stanley Stanley-Yao

🏠
Working from home
View GitHub Profile
@Stanley-Yao
Stanley-Yao / reduce-reducers-example.js
Created November 11, 2018 21:56 — forked from markerikson/reduce-reducers-example.js
Redux reduce-reducers example
const mainReducer = combineReducers({a, b, c});
const secondReducer = function(state, action) {
switch(action.type) {
case SOME_ACTION:
return someSpecificReducer(state.a, state.c);
default: return state;
}
};
@Stanley-Yao
Stanley-Yao / get-ref-width.tsx
Last active August 15, 2021 03:56
get-ref-width
import React, { useEffect, useRef, useState } from "react";
const AppBeta = () => {
const [width, setWidth] = useState<number>(window.innerWidth);
const [widgetBWidth, setWidgetBWidth] = useState<number | undefined>();
const widgetBContainer = useRef<HTMLDivElement>(null);
const updateWidth = () => {
setWidth(window.innerWidth);
import React, { useEffect, useState, useCallback } from "react";
import { useResizeDetector } from "react-resize-detector";
const AppGamma = () => {
const [widthA, setWidthA] = useState<number>(800);
const onResize = useCallback(() => {
// on resize logic
}, []);
const { width, ref } = useResizeDetector({