Appearance
Contributing
Thanks for being interested in contributing to this project! reause is an experimental 1:1 React port of VueUse: the upstream repo is pinned as a git submodule at source/vueuse and is the single source of truth for every mapping.
Development
Setup
Clone this repo to your local machine and install the dependencies.
bash
git clone --recurse-submodules https://github.com/hairyf/reause.git
cd reause
pnpm installWindows note: if you cloned without
--recurse-submodules, rungit submodule update --init --recursiveto fetchsource/vueuse.
We use VitePress for rapid development and documenting. You can start it locally by
bash
npm run docsTesting
bash
pnpm test:unit # to run unit testsHook tests run in a real browser via vitest-browser-react. You need to install the Playwright browsers once:
bash
npx playwright install --with-depsand then run
bash
pnpm test:browserContributing
Existing functions
Feel free to enhance the existing functions. Please try not to introduce breaking changes.
New functions
There are some notes for adding new functions (ported from VueUse):
- Before you start working, it's better to open a mapping issue to discuss first.
- The implementation should be placed under
packages/<pkg>/<fn>as a folder and exposed in the package barrelpackages/<pkg>/index.ts. - In the
corepackage, try not to introduce 3rd-party dependencies as this package is aimed to be as lightweight as possible. - If you'd like to introduce 3rd-party dependencies, please contribute to
@reause/integrationsor create a new add-on. - When writing documentation for your function, mirror the upstream
index.mdstructure (React differences only in JSDoc).
Please note the barrel line is not generated: add
export * from './<fn>'topackages/<pkg>/index.tsby hand. Only the metadata trio (meta/functions.md,packages/functions.md,packages/metadata/src/functions.ts) is generated — by the orchestrator after the PR is merged.
New add-ons
New add-ons are greatly welcome!
- Create a new folder under
packages/, name it as your add-on name. - Add add-on details in
meta/packages.ts. - Create
README.mdunder that folder. - Add functions as you would do to the core package.
- Commit and submit as a PR.
Project Structure
Monorepo
We use monorepo for multiple packages
packages
shared/ - shared utils across packages
core/ - the core package
integrations/ - 3rd-party integrations
math/ - math utils
[...addons]/ - add-ons namedFunction Folder
A function folder typically contains these 4 files:
bash
index.tsx # function source code itself (React hook)
demo.tsx # documentation demo
index.test.tsx # vitest browser testing
index.md # documentationfor index.tsx you should export the hook with names.
tsx
// DO
export function useMyFunction() { /* ... */ }
// DON'T
export default useMyFunctionfor index.md the first sentence will be displayed as the short intro in the function list, so try to keep it brief and clear.
markdown
# useMyFunction
This will be the intro. The detail descriptions...Read more about the guidelines.
Mapping a VueUse function
Follow the mapping issue template workflow:
- Locate the upstream implementation under
source/vueuse/packages/<pkg>/<fn>. - Create
packages/<pkg>/<fn>/index.tsxwith the React port:ref()/reactive()→useState()watch()/watchEffect()→useEffect()computed()→useMemo()/useCallback()- composable teardown → effect cleanup on unmount
- Export it from
packages/<pkg>/index.ts. - Add a test in
packages/<pkg>/<fn>/index.test.tsxusingvitest-browser-react, mirroring the upstream test files. - Do not edit or regenerate the metadata trio (
meta/functions.md,packages/functions.md,packages/metadata/src/functions.ts). It is generated by the orchestrator after the PR is merged. - Add a docs page
packages/<pkg>/<fn>/index.md+ a co-located demopackages/<pkg>/<fn>/demo.tsx.
Code Style
Don't worry about the code style as long as you install the dev dependencies. Git hooks will format and fix them for you on committing (eslint via @antfu/eslint-config, the same config VueUse uses).
Commit conventions
Follow Conventional Commits, e.g. feat(core): port useMouse, fix(shared): …, docs: ….
PR checklist
- [ ]
npm run typecheckpasses - [ ]
npm run testpasses - [ ]
npm run lintpasses - [ ]
meta/functions.mduntouched — the metadata trio is regenerated by the orchestrator after merge