Skip to content

Instantly share code, notes, and snippets.

@nodahikaru
Created June 4, 2020 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nodahikaru/9886180f5cf6c1128d03a71fdb35bdda to your computer and use it in GitHub Desktop.
Save nodahikaru/9886180f5cf6c1128d03a71fdb35bdda to your computer and use it in GitHub Desktop.
ScreenConsumer for global usable using Context API
import React from "react";
import PropTypes from "prop-types";
import DimensionConsumer from "./DimensionContext";
import { getScreenWidth, getScreenHeight } from "./selectors";
const ScreenConsumer = ({ children }) => {
return (
<DimensionConsumer>
{dimensions =>
children(getScreenWidth(dimensions), getScreenHeight(dimensions))
}
</DimensionConsumer>
);
};
ScreenConsumer.propTypes = {
children: PropTypes.func.isRequired
};
export default ScreenConsumer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment