Skip to content

Commit

Permalink
Add React 16 note
Browse files Browse the repository at this point in the history
close #67
  • Loading branch information
yesmeck committed Oct 16, 2017
1 parent 8e7ca0b commit 88066a6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

- add action `contextMenu`

## 2.0.0
## 2.0.0 / 2017-09-25

- support React 16

Expand Down
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,64 @@ npm run coverage

open coverage/ dir

## React 16 Note

Note: If you are using React 16, you won't access popup element's ref in parent component's componentDidMount, which means following code won't work.

```javascript
class App extends React.Component {
componentDidMount() {
this.input.focus(); // error, this.input is undefined.
}

render() {
return (
<Trigger
action={['click']}
popup={<div><input ref={node => this.input = node} type="text" /></div>}
>
<button>click</button>
</Trigger>
)
}
}
```

Consider wrap your popup element to a separate component:

```javascript
class InputPopup extends React.Component {
componentDidMount() {
this.onMount();
}

render() {
return (
<div>
<input ref={this.props.inputRef} type="text" />
</div>
);
}
}

class App extends React.Component {
handlePopupMount() {
this.input.focus(); // error, this.input is undefined.
}

render() {
return (
<Trigger
action={['click']}
popup={<InputPopup inputRef={node => this.input = node} onMount={this.handlePopupMount} />}
>
<button>click</button>
</Trigger>
)
}
}
```

## License

rc-trigger is released under the MIT license.

1 comment on commit 88066a6

@yesmeck
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.