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

provide optional targetWindow prop #78

Merged
merged 4 commits into from
Jan 30, 2018
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
5 changes: 2 additions & 3 deletions modules/Media.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class Media extends React.Component {
};

static defaultProps = {
defaultMatches: true,
targetWindow: window
defaultMatches: true
};

state = {
Expand All @@ -31,7 +30,7 @@ class Media extends React.Component {

componentWillMount() {
let { query } = this.props;
const { targetWindow } = this.props;
const targetWindow = this.props.targetWindow || window;
Copy link
Member

Choose a reason for hiding this comment

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

This still breaks server-side rendering because componentWillMount fires on the server but window is not defined.


if (typeof targetWindow !== "object") return;
Copy link
Member

Choose a reason for hiding this comment

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

This is the line that checks to make sure we're actually in a browser. It should stay:

if (typeof window !== 'object') return;

and then get the targetWindow prop afterwards.


Expand Down