I set it to es2018, but still get error TS2802: Type 'IterableIterator<number>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
with bunchee version 2.2.0
can bunchee use typescript ouput version?
docs(useEvent): add comment
feat: add useOnceEffect useOnceLayoutEffect
chore: release v1.1.4
a simple hook can do this
const record = new WeakSet();
export const useOnceEffect = (fn: any, dep: any) => {
const onceWrapper = () => {
const shouldStart= !record.has(fn);
if(shouldStart){
record.add(fn);
fn();
}
}
useEffect(onceWrapper, dep);
};
update: a new solution
import { useId } from "react";
const record = new Set();
export const useOnce = (fn: any) => {
const id = useId();
const shouldStart = !record.has(id);
if (shouldStart) {
record.add(id);
fn();
}
};
it works well in lateset nextjs framework
if you want useEffect run once, just do this
export const useOnceEffect = (fn: any, dep: any) => {
const record = new WeakSet();
const onceWrapper = () => {
const shouldStart= !record.has(fn);
if(shouldStart){
record.add(fn);
fn();
}
}
useEffect(onceWrapper, dep);
};
hi, here useControlled
feat: add useControlled
chore: release v1.1.3
feat: useFocus
feat: useFocus
chore: release v1.1.2
I find a possible solution.
let lock = false;
function Home() {
if(!lock){
lock = true;
console.log('do something')
}
return <div></div>
useRef will also exec twice