Skip to content

Commit

Permalink
fix: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Qun committed Aug 24, 2024
1 parent f5b12e9 commit cdb4231
Showing 1 changed file with 34 additions and 37 deletions.
71 changes: 34 additions & 37 deletions examples/demo-02/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,90 +1,87 @@
import { useEffect, useState, useRef } from "react";
import { atom, useAtom } from "jotai";
import { useEffect, useState, useRef } from 'react'
import { atom, useAtom } from 'jotai'
import {
useAtomWithSchedule,
NormalPriority,
ImmediatePriority,
} from "jotai-scheduler";
} from 'jotai-scheduler'

const anAtom = atom(0);
const anAtom = atom(0)

const simulateHeavyRender = () => {
const start = performance.now();
const start = performance.now()
while (performance.now() - start < 10) {}
};
}

function useIsVisible() {
const ref = useRef(null);
const [isVisible, setIsVisible] = useState(false);
const ref = useRef(null)
const [isVisible, setIsVisible] = useState(false)

useEffect(() => {
const observer = new IntersectionObserver(
([entry]) => {
setIsVisible(entry.isIntersecting);
}
);
const observer = new IntersectionObserver(([entry]) => {
setIsVisible(entry.isIntersecting)
})

if (ref.current) {
observer.observe(ref.current);
observer.observe(ref.current)
}

return () => {
if (ref.current) {
observer.unobserve(ref.current);
observer.unobserve(ref.current)
}
};
}, [ref]);
}
}, [ref])

return [ref, isVisible] as const;
return [ref, isVisible] as const
}

const Item = () => {
simulateHeavyRender();
const [ref, isVisible] = useIsVisible();
simulateHeavyRender()
const [ref, isVisible] = useIsVisible()
// const [num, setNum] = useAtom(anAtom);
const [num, setNum] = useAtomWithSchedule(anAtom, {
priority: isVisible ? ImmediatePriority : NormalPriority,
});
})
return (
<div
ref={ref}
style={{
height: "50px",
width: "50%",
margin: "10px",
textAlign: "center",
border: "2px solid black",
height: '50px',
width: '50%',
margin: '10px',
textAlign: 'center',
border: '2px solid black',
}}
>
<div>
{num} {isVisible ? "visible" : "not visible"}
{num} {isVisible ? 'visible' : 'not visible'}
</div>
<button
onClick={() => {
setNum(num + 1);
setNum(num + 1)
}}
>
+1
</button>
</div>
);
};
)
}

export const App = () => {
const items = new Array(100).fill(0);
const items = new Array(100).fill(0)

return (
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
}}
>
{items.map(() => (
<Item />
))}
</div>
);
};

)
}

0 comments on commit cdb4231

Please sign in to comment.