Skip to content

Commit

Permalink
Rename react submodule to hook
Browse files Browse the repository at this point in the history
So that Typescript doesn't think it is the typings for React itself
  • Loading branch information
Alduino committed Jan 25, 2022
1 parent 5bb5902 commit 768bcca
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ isInvalid(result) // true

> You need React to be installed to use these hooks. You’ll get a module not found error if it isn’t.
Yoogi comes built-in with a React hook, `useValidation`, which you can import from `@radiantguild/yoogi/react`. You don’t have to use it if you don’t want to, but it is there if you do. (You can [view its source](./src/react.ts) to help you implement your own).
Yoogi comes built-in with a React hook, `useValidation`, which you can import from `@radiantguild/yoogi/hook`. You don’t have to use it if you don’t want to, but it is there if you do. (You can [view its source](./src/hook.ts) to help you implement your own).

The hook takes the source string and validators, just like the normal validate function. The hook will call `validate` initially, and then when either the source or one of the validators changes.

Expand Down Expand Up @@ -120,6 +120,8 @@ The validate function returns the validation result, which has the following pro

### `useValidation` hook

> This function is from `@radiantguild/yoogi/hook`, as it requires an extra dependency on React.
Passed the same parameters as `validate` (see above). Calls validate once initially and then whenever the source or one of the validators changes. Triggers renders automatically when the validation result changes, including re-calling validate, or when asynchronous validation completes.

Returns the same result as `validate`, but with an extra property `read`, which will suspend rendering of the component in which it is called until the data is ready, and then it will return the data.
Returns the same result as `validate`, but with an extra property `read`, which will suspend rendering of the component in which it is called until the data is ready, and then it will return the data.
1 change: 1 addition & 0 deletions hook.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dist/hook";
1 change: 0 additions & 1 deletion react.d.ts

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export const tsup: Options = {
clean: true,
dts: true,
sourcemap: true,
entry: ["src/index.ts", "src/react.ts"],
entry: ["src/index.ts", "src/hook.ts"],
format: ["esm"]
};

0 comments on commit 768bcca

Please sign in to comment.