Skip to content

Commit

Permalink
fix some README typo
Browse files Browse the repository at this point in the history
  • Loading branch information
bySabi committed Mar 18, 2019
1 parent cd1f5d1 commit 86f1530
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions example/pages/mouse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { useState, useEffect } from 'react';
import { createHook } from 'hookleton';

const useMousePosition = createHook(() => {
const [position, setPosition] = useState({ x: null, y: null });

const handleMouseMove = e => setPosition({ x: e.pageX, y: e.pageY });

useEffect(() => {
window.addEventListener('mousemove', handleMouseMove);
return () => window.removeEventListener('mousemove', handleMouseMove);
}, []);

return [position];
});

const MouseHost = () => (useMousePosition.use(), null);

const Mouse = () => {
const [mousePosition] = useMousePosition();
return (
<div style={{ borderStyle: 'solid' }}>
x: {mousePosition.x}, y: {mousePosition.y}
</div>
);
};

// put <Mouse /> in a table of 1x12 cells
const TableMouse = () => (
<table>
<tbody>
<tr>
{Array.from({ length: 12 }).map((_, idx) => (
<td key={idx}>
<Mouse />
</td>
))}
</tr>
</tbody>
</table>
);

// repeat <TableMouse /> 100 times
export default () => (
<>
<MouseHost />
<ul style={{ listStyle: 'none' }}>
{Array.from({ length: 100 }).map((_, idx) => (
<li key={idx}>
<TableMouse />
</li>
))}
</ul>
</>
);

0 comments on commit 86f1530

Please sign in to comment.