File tree Expand file tree Collapse file tree 4 files changed +23
-11
lines changed Expand file tree Collapse file tree 4 files changed +23
-11
lines changed Original file line number Diff line number Diff line change 1
- # ` @rehooks/DocumentTitle `
1
+ # ` @rehooks/document-title `
2
2
3
- > React hook for DocumentTitle
3
+ > React hook for updating the document-title
4
4
5
5
> ** Note:** This is using the new [ React Hooks API Proposal] ( https://reactjs.org/docs/hooks-intro.html )
6
6
> which is subject to change until React 16.7 final.
10
10
## Install
11
11
12
12
``` sh
13
- yarn add @rehooks/DocumentTitle
13
+ yarn add @rehooks/document-title
14
14
```
15
15
16
16
## Usage
17
17
18
18
``` js
19
- import useDocumentTitle from ' @rehooks/DocumentTitle ' ;
19
+ import useDocumentTitle from ' @rehooks/document-title ' ;
20
20
21
21
function MyComponent () {
22
- let value = useDocumentTitle ();
23
- // value == DocumentTitle
22
+ useDocumentTitle (' Page Title' );
24
23
return < div/ > ;
25
24
}
26
25
```
Original file line number Diff line number Diff line change 1
- import React from "react" ;
1
+ import React , { useState } from "react" ;
2
2
import { render } from "react-dom" ;
3
3
import useDocumentTitle from "./" ;
4
4
5
5
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
+ ) ;
8
17
}
9
18
10
19
render ( < App /> , window . root ) ;
Original file line number Diff line number Diff line change 1
- export default function useDocumentTitle ( title : string ) ;
1
+ interface DocumentTitle { }
2
+
3
+ export default function useDocumentTitle ( title : string ) : DocumentTitle ;
Original file line number Diff line number Diff line change 1
- export default function useDocumentTitle(title: string);
1
+ interface DocumentTitle {}
2
+
3
+ export default function useDocumentTitle(title: string): DocumentTitle;
You can’t perform that action at this time.
0 commit comments