Skip to content

Instantly share code, notes, and snippets.

@505aaron
Last active April 19, 2018 14:31
Show Gist options
  • Save 505aaron/64c2fc3ef374c075a86c617474ec9f31 to your computer and use it in GitHub Desktop.
Save 505aaron/64c2fc3ef374c075a86c617474ec9f31 to your computer and use it in GitHub Desktop.
Medium Gist
// Use the provider anywhere in your tree. The easiest example
// being the root.
export default () => (
<DimensionProvider>
<App />
</DimensionProvider>
);
// Use the consumers in descendant nodes of the provider.
const DimensionAwareComponent () => (
<View>
<ScreenConsumer>
{(width, height) => (
<View>
<Text>Width {width}</Text>
<Text>Height {height}</Text>
</View>
)}
</ScreenConsumer>
<WindowConsumer>
{(width, height) => (
<View>
<Text>Width {width}</Text>
<Text>Height {height}</Text>
</View>
)}
</WindowConsumer>
</View>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment