Skip to content

Commit

Permalink
fix(readme): simplify basic example
Browse files Browse the repository at this point in the history
  • Loading branch information
cxspxr committed Oct 26, 2022
1 parent e46a209 commit c03f523
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ Run function on every animation frame
import React, { useCallback, useState } from "react";
import { useAnimationFrame } from "use-listen-on-animation-frame";

const getDate = () => new Date();

const Component = () => {
const [date, setDate] = useState(getDate());
const [date, setDate] = useState(new Date());

const setDateOnAnimationFrame = useCallback(() => {
setDate(getDate());
const syncDate = useCallback(() => {
setDate(new Date());
}, []);

useAnimationFrame(setDateOnAnimationFrame);
useAnimationFrame(syncDate);

return <div>{date}</div>;
};
Expand Down
10 changes: 4 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ Run function on every animation frame
import React, { useCallback, useState } from "react";
import { useAnimationFrame } from "use-listen-on-animation-frame";

const getDate = () => new Date();

const Component = () => {
const [date, setDate] = useState(getDate());
const [date, setDate] = useState(new Date());

const setDateOnAnimationFrame = useCallback(() => {
setDate(getDate());
const syncDate = useCallback(() => {
setDate(new Date());
}, []);

useAnimationFrame(setDateOnAnimationFrame);
useAnimationFrame(syncDate);

return <div>{date}</div>;
};
Expand Down

0 comments on commit c03f523

Please sign in to comment.