Skip to content

Commit

Permalink
refactor: hooks to packages
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Aug 10, 2022
1 parent 03dacdb commit 3ecbf06
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/grumpy-rice-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chakra-ui/react-use-update-effect": patch
---

Initial release
6 changes: 6 additions & 0 deletions hooks/use-callback-ref/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@
"clean": "rimraf dist .turbo",
"typecheck": "tsc --noEmit",
"build:fast": "tsup src/index.ts --format=esm,cjs"
},
"peerDependencies": {
"react": ">=18"
},
"devDependencies": {
"react": "^18.0.0"
}
}
6 changes: 6 additions & 0 deletions hooks/use-controllable-state/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,11 @@
},
"dependencies": {
"@chakra-ui/react-use-callback-ref": "workspace:*"
},
"peerDependencies": {
"react": ">=18"
},
"devDependencies": {
"react": "^18.0.0"
}
}
24 changes: 24 additions & 0 deletions hooks/use-update-effect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# @chakra-ui/use-update-effect

A Quick description of the component

> This is an internal utility, not intended for public usage.
## Installation

```sh
yarn add @chakra-ui/react-use-update-effect
# or
npm i @chakra-ui/react-use-update-effect
```

## Contribution

Yes please! See the
[contributing guidelines](https://github.com/chakra-ui/chakra-ui/blob/master/CONTRIBUTING.md)
for details.

## Licence

This project is licensed under the terms of the
[MIT license](https://github.com/chakra-ui/chakra-ui/blob/master/LICENSE).
1 change: 1 addition & 0 deletions hooks/use-update-effect/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./src"
42 changes: 42 additions & 0 deletions hooks/use-update-effect/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@chakra-ui/react-use-update-effect",
"version": "1.0.0",
"description": "",
"keywords": [
"use-update-effect"
],
"author": "Segun Adebayo <sage@adebayosegun.com>",
"homepage": "https://github.com/chakra-ui/chakra-ui#readme",
"license": "MIT",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"sideEffects": false,
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/chakra-ui/chakra-ui.git",
"directory": "packages/use-update-effect"
},
"bugs": {
"url": "https://github.com/chakra-ui/chakra-ui/issues"
},
"scripts": {
"build": "tsup src/index.ts --format=esm,cjs --dts",
"dev": "pnpm build -- --watch",
"clean": "rimraf dist .turbo",
"typecheck": "tsc --noEmit",
"build:fast": "tsup src/index.ts --format=esm,cjs"
},
"peerDependencies": {
"react": ">=18"
},
"devDependencies": {
"react": "^18.0.0"
}
}
26 changes: 26 additions & 0 deletions hooks/use-update-effect/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useEffect, useRef } from "react"

export function useUpdateEffect(
callback: React.EffectCallback,
deps: React.DependencyList,
) {
const renderCycleRef = useRef(false)
const effectCycleRef = useRef(false)

useEffect(() => {
const mounted = renderCycleRef.current
const run = mounted && effectCycleRef.current
if (run) {
return callback()
}
effectCycleRef.current = true
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps)

useEffect(() => {
renderCycleRef.current = true
return () => {
renderCycleRef.current = false
}
}, [])
}
6 changes: 6 additions & 0 deletions plop/component/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@
"clean": "rimraf dist .turbo",
"typecheck": "tsc --noEmit",
"build:fast": "tsup src/index.ts --format=esm,cjs"
},
"peerDependencies": {
"react": ">=18"
},
"devDependencies": {
"react": "^18.0.0"
}
}
14 changes: 13 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit 3ecbf06

@vercel
Copy link

@vercel vercel bot commented on 3ecbf06 Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.