Skip to content

Commit

Permalink
feat: 🎉 init project
Browse files Browse the repository at this point in the history
  • Loading branch information
brickspert committed Jun 28, 2019
1 parent 78cafc7 commit 744f973
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .editorconfig
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
16 changes: 16 additions & 0 deletions .fatherrc.ts
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;
8 changes: 8 additions & 0 deletions .gitignore
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
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/*.md
**/*.mdx
package.json
.umi
.umi-production
11 changes: 11 additions & 0 deletions .prettierrc
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" }
}
]
}
13 changes: 12 additions & 1 deletion README.md
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
40 changes: 40 additions & 0 deletions package.json
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"
}
3 changes: 3 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import useTitle from './useTitle';

export { useTitle };
16 changes: 16 additions & 0 deletions src/useTitle/__tests__/index.test.ts
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');
});
});
29 changes: 29 additions & 0 deletions src/useTitle/index.mdx
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);
```
9 changes: 9 additions & 0 deletions src/useTitle/index.ts
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;
17 changes: 17 additions & 0 deletions tsconfig.json
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
}
}

0 comments on commit 744f973

Please sign in to comment.