forked from alibaba/hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78cafc7
commit 744f973
Showing
12 changed files
with
182 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[Makefile] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { IBundleOptions } from 'father-build'; | ||
|
||
const options: IBundleOptions = { | ||
entry: 'src/index.tsx', | ||
esm: 'rollup', | ||
cjs: 'rollup', | ||
preCommit: { | ||
eslint: true, | ||
prettier: true | ||
}, | ||
doc: { | ||
title: '@umijs/hooks' | ||
} | ||
}; | ||
|
||
export default options; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/yarn.lock | ||
/package-lock.json | ||
/dist | ||
/.docz | ||
/node_modules | ||
/.history | ||
/.idea | ||
/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
**/*.md | ||
**/*.mdx | ||
package.json | ||
.umi | ||
.umi-production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"printWidth": 100, | ||
"overrides": [ | ||
{ | ||
"files": ".prettierrc", | ||
"options": { "parser": "json" } | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
# hooks | ||
# @umi/hooks | ||
|
||
react hooks library | ||
|
||
## Usage | ||
|
||
```sh | ||
umi block https://github.com/https://github.com/umijs/hooks/tree/master/hooks | ||
``` | ||
|
||
## LICENSE | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "hooks", | ||
"version": "0.0.1", | ||
"description": "react hooks library", | ||
"keywords": [ | ||
"umi hooks", | ||
"react hooks" | ||
], | ||
"main": "dist/index.js", | ||
"module": "dist/index.esm.js", | ||
"authors": { | ||
"name": "brickspert", | ||
"email": "[email protected]" | ||
}, | ||
"repository": "https://github.com/umijs/hooks", | ||
"scripts": { | ||
"start": "npm run dev", | ||
"dev": "father doc dev", | ||
"build": "father build", | ||
"test": "father test", | ||
"cov": "father test --coverage", | ||
"help": "father help", | ||
"precommit": "father pre-commit", | ||
"pub:npm": "npm run build & father publish --registry=https://www.npmjs.com", | ||
"pub:doc": "father doc build & father doc deploy" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8.0" | ||
}, | ||
"devDependencies": { | ||
"@testing-library/react-hooks": "^1.0.4", | ||
"@types/jest": "^24.0.15", | ||
"father": "^2.13.3", | ||
"typescript": "^3.3.3" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
}, | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import useTitle from './useTitle'; | ||
|
||
export { useTitle }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import useTitle from '../index'; | ||
|
||
describe('useTitle', () => { | ||
it('should be defined', () => { | ||
expect(useTitle).toBeDefined(); | ||
}); | ||
|
||
const hook = renderHook(props => useTitle(props), { initialProps: 'My page title' }); | ||
|
||
it('should update document title', () => { | ||
expect(document.title).toBe('My page title'); | ||
hook.rerender('My other page title'); | ||
expect(document.title).toBe('My other page title'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
name: useTitle | ||
route: / | ||
order: -1 | ||
sidebar: true | ||
--- | ||
|
||
# useTitle | ||
|
||
React side-effect hook that set title of the page. | ||
|
||
## Usage | ||
|
||
### Demo | ||
``` | ||
import {useTitle} from '@umi/hooks'; | ||
const Demo = () => { | ||
useTitle('Hello world!'); | ||
return null; | ||
}; | ||
``` | ||
|
||
## Reference | ||
|
||
``` | ||
useTitle(title: string); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { useEffect } from 'react'; | ||
|
||
const useTitle = (title: string) => { | ||
useEffect(() => { | ||
document.title = title; | ||
}, [title]); | ||
}; | ||
|
||
export default useTitle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"importHelpers": true, | ||
"jsx": "react", | ||
"esModuleInterop": true, | ||
"sourceMap": true, | ||
"baseUrl": ".", | ||
"strict": true, | ||
"paths": { | ||
"@/*": ["src/*"] | ||
}, | ||
"allowSyntheticDefaultImports": true | ||
} | ||
} |