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

Check if manager is not null for update and unmount and fix the doc #995

Merged
merged 4 commits into from
Apr 18, 2019
Merged
Changes from 1 commit
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
Next Next commit
fix: check if manager is not null for update and unmount
  • Loading branch information
Taym95 committed Apr 15, 2019
commit ea3b63f83eca9b9c1702f1d6c806d75e155829ad
16 changes: 16 additions & 0 deletions src/components/Portal/PortalConsumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,26 @@ export default class PortalConsumer extends React.Component<Props> {
}

componentDidUpdate() {
if (!this.props.manager) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please extract this condition to separate class method? Do not forget to prefix the name with _ as it is a private method and place it before just before render function. Thank you for the PR!

Copy link
Contributor

Choose a reason for hiding this comment

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

Or extract just error throwing. Decide what will be better for readability.

throw new Error(
'Looks like you forgot to wrap your root component with `Provider` component from `react-native-paper`.\n\n' +
"Please read our getting-started guide and make sure you've followed all the required steps.\n\n" +
'https://callstack.github.io/react-native-paper/getting-started.html'
);
}

this.props.manager.update(this._key, this.props.children);
}

componentWillUnmount() {
if (!this.props.manager) {
throw new Error(
'Looks like you forgot to wrap your root component with `Provider` component from `react-native-paper`.\n\n' +
"Please read our getting-started guide and make sure you've followed all the required steps.\n\n" +
'https://callstack.github.io/react-native-paper/getting-started.html'
);
}

this.props.manager.unmount(this._key);
}

Expand Down