Skip to content

Commit

Permalink
added a prop for arrows without animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Yixin Hu committed Jan 23, 2024
1 parent d953c75 commit 2ad7026
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/components/FillArrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import '../styles/FillArrow.scss';
interface FillArrowProps {
text1: string;
text2: string;
noAnimation?: boolean;
}

function useIsInViewport(ref) {
Expand All @@ -29,14 +30,16 @@ function useIsInViewport(ref) {
}

function FillArrow(props: FillArrowProps): JSX.Element {
const { text1, text2, noAnimation } = props;

const ref = useRef(null);

const isInViewport = useIsInViewport(ref);

const [animate, setAnimate] = useState(false);

useEffect(() => {
if (isInViewport && !animate) setAnimate(true);
if (isInViewport && !animate && !noAnimation) setAnimate(true);
}, [isInViewport, animate]);

return (
Expand Down
6 changes: 5 additions & 1 deletion src/pages/Lesson3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ const Lesson3: FC = () => {
store the address of <span className="code">myVariable</span>:
</p>
<div className="diagram">
<FillArrow text1="myPointer" text2="myVariable" />
<FillArrow
text1="myPointer"
text2="myVariable"
noAnimation={true}
/>
</div>
<p>
The <span className="code">&</span> operator gives you the address
Expand Down
6 changes: 5 additions & 1 deletion src/pages/Lesson4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ const Lesson4: FC = () => {
<div className="page-wrapper">
<h1>Dereferencing Pointers</h1>
<div className="diagram">
<FillArrow text1="myPointer" text2="myVariable" />
<FillArrow
text1="myPointer"
text2="myVariable"
noAnimation={true}
/>
</div>
<p>
Now you might be wondering, what good will knowing an address do?
Expand Down

0 comments on commit 2ad7026

Please sign in to comment.