This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function usePrevious(value) { | |
const ref = useRef(); | |
useEffect(() => { | |
ref.current = value; //assign the value of ref to the argument | |
}, [value]); //this code will run when the value of 'value' changes | |
return ref.current || {}; //in the end, return the current ref value. | |
} | |
export { usePrevious }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr1 = [ | |
'common', 'testma', | |
'xchaos', 'xcrab', | |
'xfiregod', 'xsea', | |
'xshelter', 'zeus' | |
]; | |
var arr2 = [ | |
'common', 'xsea', | |
'testma', 'xchaos', | |
'xcrab', 'xshelter', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const glob = require('glob'); | |
const fs = require('fs-extra'); | |
const HeavenIcons = require('@perfma/icons'); | |
const filePath = './src/pages/License/components/StepArea.tsx'; // process.argv[2]; | |
// Usage | |
// node index.js ../foo/\*.js | |
// console.log('HeavenIcons', HeavenIcons); | |
glob(filePath, (err, files) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SetStateAction, useCallback, useEffect, useRef, useState } from 'react'; | |
type Callback<T> = (value?: T) => void; | |
type DispatchWithCallback<T> = (value: T, callback?: Callback<T>) => void; | |
function useStateCallback<T>(initialState: T | (() => T)): [T, DispatchWithCallback<SetStateAction<T>>] { | |
const [state, _setState] = useState(initialState); | |
const callbackRef = useRef<Callback<T>>(); | |
const isFirstCallbackCall = useRef<boolean>(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useState } from 'react' | |
export type MapOrEntries<K, V> = Map<K, V> | [K, V][] | |
// Public interface | |
export interface Actions<K, V> { | |
set: (key: K, value: V) => void | |
setAll: (entries: MapOrEntries<K, V>) => void | |
remove: (key: K) => void | |
reset: Map<K, V>['clear'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useEffect, useRef } from 'react' | |
function useIsMounted() { | |
const isMounted = useRef(false) | |
useEffect(() => { | |
isMounted.current = true | |
return () => { | |
isMounted.current = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 数组去重对象 | |
var arr = [ | |
{ id: 1, city: "南京" }, | |
{ id: 2, city: "南京" }, | |
{ id: 3, city: "杭州" }, | |
{ id: 4, city: "广州" }, | |
]; | |
var newArr = arr.reduce((prev, cur) => { | |
obj[cur.city] ? "" : (obj[cur.city] = true && prev.push(cur)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SUBSTRING_TO_FIND = '-precache-'; | |
export default async function deleteWorkboxPreCaches( | |
filename: string, | |
substringToFind: string = SUBSTRING_TO_FIND, | |
) { | |
const cacheNames = await caches.keys(); | |
const cacheNamesToDelete = cacheNames.filter(cacheName => { | |
return cacheName.includes(substringToFind); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @Author: trigkit4 | |
* @Date: 2018-09-18 10:07:05 | |
*/ | |
import React, { Component, ComponentType } from 'react'; | |
import { computed, action, observable } from 'mobx'; | |
import { observer } from 'mobx-react'; | |
import _ from 'lodash'; | |
type BuildContainerOptions<T> = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _toString = Object.prototype.toString; | |
/** | |
* Strict object type check. Only returns true | |
* for plain JavaScript objects. | |
*/ | |
function isPlainObject (obj) { | |
return _toString.call(obj) === '[object Object]' | |
} |
NewerOlder