Skip to content

Conversation

@olistic
Copy link
Contributor

@olistic olistic commented Jul 31, 2018

This closes #94.

Sorry I couldn't wait for confirmation on #94, but I needed this feature. I'm using my fork for the time being, but I'd prefer to go back to using the original pkg once (and if) this is merged here.

Thanks! 😄

modules/Media.js Outdated

const { onQueryStateChange } = this.props;
if (onQueryStateChange) {
this.mediaQueryList.addListener(onQueryStateChange);
Copy link
Member

Choose a reason for hiding this comment

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

We already have a listener registered in updateMatches. We should call the onChange callback there instead of registering it as a separate listener.

modules/Media.js Outdated
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
targetWindow: PropTypes.object
targetWindow: PropTypes.object,
onQueryStateChange: PropTypes.func
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't forget to rename it to onChange, as per @mjackson's comment.

@olistic olistic force-pushed the onquerystatechange-callback branch from 9738a31 to 8b5e738 Compare August 27, 2018 17:36
@olistic olistic changed the title Add onQueryStateChange callback Add onChange callback Aug 27, 2018
@olistic
Copy link
Contributor Author

olistic commented Aug 27, 2018

@mjackson just made your suggested changes and I'm happy with the final result. The onChange callback now receives the matches result directly instead of an instance of MediaQueryListEvent. Much cleaner!

@edorivai edorivai merged commit d286ecd into ReactTraining:master Aug 30, 2018
@edorivai
Copy link
Collaborator

This LGTM, I went ahead and merged it in!

@mjackson let me know if you want some stuff tweaked afterwards.

@olistic olistic deleted the onquerystatechange-callback branch October 10, 2018 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

onQueryStateChange callback

3 participants