Skip to content

Commit e728e14

Browse files
Update the example, and readme
1 parent 24dbd83 commit e728e14

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# `@rehooks/DocumentTitle`
1+
# `@rehooks/document-title`
22

3-
> React hook for DocumentTitle
3+
> React hook for updating the document-title
44
55
> **Note:** This is using the new [React Hooks API Proposal](https://reactjs.org/docs/hooks-intro.html)
66
> which is subject to change until React 16.7 final.
@@ -10,17 +10,16 @@
1010
## Install
1111

1212
```sh
13-
yarn add @rehooks/DocumentTitle
13+
yarn add @rehooks/document-title
1414
```
1515

1616
## Usage
1717

1818
```js
19-
import useDocumentTitle from '@rehooks/DocumentTitle';
19+
import useDocumentTitle from '@rehooks/document-title';
2020

2121
function MyComponent() {
22-
let value = useDocumentTitle();
23-
// value == DocumentTitle
22+
useDocumentTitle('Page Title');
2423
return <div/>;
2524
}
2625
```

example.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
import React from "react";
1+
import React, { useState } from "react";
22
import { render } from "react-dom";
33
import useDocumentTitle from "./";
44

55
function App() {
6-
useDocumentTitle("page Title");
7-
return <div />;
6+
return <NestedComponent />;
7+
}
8+
9+
function NestedComponent() {
10+
const [value, setValue] = useState("page title");
11+
useDocumentTitle(value);
12+
return (
13+
<div>
14+
<input value={value} onChange={e => setValue(e.target.value)} />
15+
</div>
16+
);
817
}
918

1019
render(<App />, window.root);

index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export default function useDocumentTitle(title: string);
1+
interface DocumentTitle {}
2+
3+
export default function useDocumentTitle(title: string): DocumentTitle;

index.js.flow

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export default function useDocumentTitle(title: string);
1+
interface DocumentTitle {}
2+
3+
export default function useDocumentTitle(title: string): DocumentTitle;

0 commit comments

Comments
 (0)