Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If application root is reinitialized, update ActionSheet and Toast refs #1700

Merged
merged 2 commits into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dist/src/basic/Root.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/basic/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class Root extends Component {
{this.props.children}
<Toast
ref={c => {
if (!Toast.toastInstance) Toast.toastInstance = c;
if (c) Toast.toastInstance = c;
Copy link

@douglasjunior douglasjunior May 15, 2018

Choose a reason for hiding this comment

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

I think you don't need to check if c is valid. Just do the assignment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for taking a look at this @douglasjunior. Does GeekyAnts have a preference on how to handle the case where c is null? @akhil-geekyants @SupriyaKalghatgi

Choose a reason for hiding this comment

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

https://reactjs.org/docs/refs-and-the-dom.html#callback-refs

React will call the ref callback with the DOM element when the component mounts, and call it with null when it unmounts. ref callbacks are invoked before componentDidMount or componentDidUpdate lifecycle hooks.

I think if the component has been unmounted, you should not keep the ref. This is memory leak.

}}
/>
<ActionSheet
ref={c => {
if (!ActionSheet.actionsheetInstance)
if (c)
ActionSheet.actionsheetInstance = c;
}}
/>
Expand Down