Skip to content

packages/core/src/lib/hooks/use-line-path.ts

Read as Markdown

This is the source snapshot used to build these API details. View this revision on GitHub.

Back to reference

1 import type { LinePathOptions } from '../geometry/line.js';
2 import { createLinePath } from '../geometry/line.js';
3 import { useValueMemoSlot } from './use-value-memo-slot.js';
4 
5 /**
6  * Creates a memoized Path2D for a set of line coordinates.
7  * @param coords - Ordered horizontal and vertical coordinate pairs.
8  * @param config - Whether to close the path by connecting its last vertex to its first.
9  * @returns A memoized Path2D
10  *
11  * @see {@link LinePathOptions}
12  * @see {@link createLinePath}
13  */
14 export function useLinePath(
15   coords: [number, number][],
16   config?: { closePath?: boolean },
17 ): Path2D {
18   return useValueMemoSlot(
19     'linePath',
20     () => createLinePath({ coords, closePath: config?.closePath }),
21     [...coords.flat(), config?.closePath],
22   );
23 }
24 

Documentation built with @pibbl/core 0.0.2, revision 2dccb19. ALPHA — NOT FOR PRODUCTION USE.