Created
June 4, 2020 07:46
-
-
Save nodahikaru/9886180f5cf6c1128d03a71fdb35bdda to your computer and use it in GitHub Desktop.
ScreenConsumer for global usable using Context API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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