Skip to content

Instantly share code, notes, and snippets.

View dukeluo's full-sized avatar
🥲

Huan dukeluo

🥲
View GitHub Profile
@dukeluo
dukeluo / withCondition.tsx
Created May 10, 2022 15:43
HOC for Conditional Rendering
import React, { FC } from 'react'
interface IConditional {
when(): boolean
}
export function withCondition<P>(Comp: FC<P>) {
return ({ when, ...rest }: P & IConditional) =>
when() ? <Comp {...((rest as unknown) as P)} /> : null
}
@dukeluo
dukeluo / debounce-throttle-ramda
Last active April 4, 2022 15:15
`debounce` and `throttle` methods in Ramda.js
`debounce` and `throttle` methods in Ramda.js
import { useCallback, useEffect, useState } from "react";
import React from "react";
import ReactDOM from "react-dom";
const Counter = () => {
const [incrementClicked, setIncrementClicked] = useState(false);
const [decrementClicked, setDecrementClicked] = useState(false);
const [count, setCount] = useState(0);
const increment = useCallback(() => {