Skip to content

Commit 8468bf4

Browse files
committed
Typedoc comments
1 parent 3ca7b4c commit 8468bf4

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ npm install @float-toolkit/react
2525

2626
### Usage
2727

28-
The package export is a **React hook** called `useFloatToolkit`. It returns an object with an `output` state, as well as math functions that also serve as setters for the output.
28+
The package export is a **React hook** called `useFloatToolkit`. It returns an object with an `output` state, as well as FloatToolkit methods that also serve as setters for the output.
2929

3030
```js
3131
import { useEffect } from "react";

src/index.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,31 @@ import { useDebugValue, useMemo, useState } from "react";
33
import FloatToolkit, { FloatToolkitOptions, FloatToolkitPrecisionInteger } from "@float-toolkit/core";
44

55
namespace ReactFT {
6+
/**
7+
* An integer between 1 and 17, which can be used as the default precision for the useFloatToolkit hook.
8+
*/
69
export type Precision = FloatToolkitPrecisionInteger;
10+
11+
/**
12+
* Options that can be set to modify the behavior of the useFloatToolkit hook.
13+
*/
714
export interface Options extends FloatToolkitOptions {}
815
}
916

17+
/**
18+
* Contains the properties and methods from the FloatToolkit class, as well as special ones for React.
19+
*/
1020
interface ReactFT {
21+
/**
22+
* An integer between 1 and 17.
23+
* Defines the precision (number of decimals) to use by default, if the precision is not specified in the method itself.
24+
*/
1125
get defaultPrecision(): ReactFT.Precision;
1226
set defaultPrecision(newPrecision: ReactFT.Precision);
1327

28+
/**
29+
* The options object used in this instance of useFloatToolkit.
30+
*/
1431
get options(): ReactFT.Options;
1532

1633
add(numbers: number[], precision?: ReactFT.Precision): number;
@@ -21,10 +38,30 @@ interface ReactFT {
2138
setOptions(options?: ReactFT.Options, resetOutput?: boolean): ReactFT.Options;
2239
subtract(numbers: number[], precision?: ReactFT.Precision): number;
2340

41+
/**
42+
* A reactive state variable containing the returned value from the last method called.
43+
*/
2444
output: number;
45+
46+
/**
47+
* Resets the output to 0.
48+
*/
2549
resetOutput(): void;
2650
}
2751

52+
/**
53+
* A React hook that returns FloatToolkit methods and an `output` state.
54+
*
55+
* @param defaultPrecision The precision (number of decimals) to use if not specified in the method itself. Can be changed later. Default value if 10.
56+
* @param options An optional configuration object.
57+
*
58+
* @example
59+
* import useFloatToolkit from "@float-toolkit/react";
60+
*
61+
* function Sum() {
62+
* const { add, output } = useFloatToolkit(2);
63+
* }
64+
*/
2865
function useFloatToolkit(defaultPrecision?: ReactFT.Precision, options?: ReactFT.Options): ReactFT {
2966
const [output, setOutput] = useState(0);
3067
useDebugValue(output);

0 commit comments

Comments
 (0)