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

Log when the context does not exist instead of throwing errors #193

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions src/Dispatcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@ export default class HelmetDispatcher extends Component<DispatcherProps> {
}

componentDidUpdate() {
if (!this.props.context.helmetInstances) {
console.trace('No helmet context was found, make sure to wrap your app in a HelmetProvider');
return;
}

this.emitChange();
}

componentWillUnmount() {
const { helmetInstances } = this.props.context;
if (!helmetInstances) {
console.trace('No helmet context was found, make sure to wrap your app in a HelmetProvider');
return;
}

helmetInstances.remove(this);
this.emitChange();
}
Expand Down Expand Up @@ -68,6 +78,11 @@ export default class HelmetDispatcher extends Component<DispatcherProps> {
this.rendered = true;

const { helmetInstances } = this.props.context;
if (!helmetInstances) {
console.trace('No helmet context was found, make sure to wrap your app in a HelmetProvider');
return;
}

helmetInstances.add(this);
this.emitChange();
}
Expand Down