|
1 | | -# react |
2 | | -A React hook wrapper for Float Toolkit |
| 1 | +<div align="center" style="margin-bottom: 0.5rem"> |
| 2 | + <img src="https://raw.githubusercontent.com/float-toolkit/react/HEAD/media/ftreact.svg" width="150" /> |
| 3 | +</div> |
| 4 | + |
| 5 | +<div align="center"> |
| 6 | + |
| 7 | +# Float Toolkit for React |
| 8 | + |
| 9 | +[](https://www.npmjs.com/package/@float-toolkit/react) |
| 10 | +[](https://www.npmjs.com/package/@float-toolkit/react) |
| 11 | + |
| 12 | +</div> |
| 13 | + |
| 14 | +A [React](https://reactjs.org/) [hook](https://reactjs.org/docs/hooks-intro.html) wrapper for [**Float Toolkit**](https://https://float-toolkit.web.app/) |
| 15 | + |
| 16 | +## Get started |
| 17 | + |
| 18 | +### Installation |
| 19 | + |
| 20 | +To add Float Toolkit to your React app, run this command: |
| 21 | + |
| 22 | +```sh-session |
| 23 | +npm install @float-toolkit/react |
| 24 | +``` |
| 25 | + |
| 26 | +### Usage |
| 27 | + |
| 28 | +The package export is a **React hook** called `useFloatToolkit`. It can be called from within a Function Component to create an outlet (reactive output). |
| 29 | + |
| 30 | +```js |
| 31 | +import React, { useEffect } from "react"; |
| 32 | +import useFloatToolkit from "@float-toolkit/react"; |
| 33 | + |
| 34 | +function Sum({ x, y }) { |
| 35 | + const { add, outlet } = useFloatToolkit(); |
| 36 | + |
| 37 | + useEffect(() => { |
| 38 | + add([x, y]); |
| 39 | + }, [x, y]); |
| 40 | + |
| 41 | + return <span className="number">{outlet}</span>; |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +### TypeScript |
| 46 | + |
| 47 | +<div align="center" style="margin: 0.5rem 0"> |
| 48 | + <img src="https://raw.githubusercontent.com/float-toolkit/react/HEAD/media/tsftreact.svg" width="100" /> |
| 49 | +</div> |
| 50 | + |
| 51 | +Just like its parent package, Float Toolkit for React is written in [TypeScript](https://www.typescriptlang.org/). You can import the `ReactFT` namespace which contains all the type declarations used by the package. |
| 52 | + |
| 53 | +#### Example: |
| 54 | + |
| 55 | +```tsx |
| 56 | +import React, { FC, useEffect } from "react"; |
| 57 | +import useFloatToolkit, { ReactFT } from "@float-toolkit/react"; |
| 58 | + |
| 59 | +interface Props { |
| 60 | + numbers: number[]; |
| 61 | + precision: ReactFT.Precision; |
| 62 | +} |
| 63 | + |
| 64 | +const Sum: FC = (props) => { |
| 65 | + const { add, outlet } = useFloatToolkit(props.precision); |
| 66 | + |
| 67 | + useEffect(() => { |
| 68 | + add(props.numbers); |
| 69 | + }, [props.numbers]); |
| 70 | + |
| 71 | + return <span className="number">{outlet}</span>; |
| 72 | +}; |
| 73 | +``` |
| 74 | + |
| 75 | +## Links |
| 76 | + |
| 77 | +- [FloatToolkit documentation (Vanilla JS)](https://float-toolkit.web.app/) |
| 78 | +- [GitHub](https://github.com/float-toolkit/react) |
| 79 | +- [npm](https://www.npmjs.com/package/@float-toolkit/react) |
| 80 | + |
| 81 | +## Contributing |
| 82 | + |
| 83 | +Before creating an issue, please consider the following: |
| 84 | + |
| 85 | +- Refer to the [FloatToolkit documentation](https://float-toolkit.web.app/) and read **this file** carefully to make sure the error is actually a bug and not a mistake of your own. |
| 86 | +- Make sure the issue hasn't already been reported or suggested. |
| 87 | +- After following these steps, you can read the [contribution guidelines](https://github.com/float-toolkit/react/blob/master/.github/CONTRIBUTING.md) and follow the steps to submit a PR. |
0 commit comments