Skip to content

Instantly share code, notes, and snippets.

@MicroBenz
Created March 10, 2018 13:39
Show Gist options
  • Save MicroBenz/66102eba6824730348d8b91fe4980fd8 to your computer and use it in GitHub Desktop.
Save MicroBenz/66102eba6824730348d8b91fe4980fd8 to your computer and use it in GitHub Desktop.
React Context
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class UIKitContext extends Component {
getChildContext() {
return {
path: (image, type) => `${this.props.prefixPath}/${type}/${image}`
};
}
render() {
return (
<div>{this.props.children}</div>
);
}
}
UIKitContext.propTypes = {
children: PropTypes.element,
prefixPath: PropTypes.string
};
UIKitContext.childContextTypes = {
path: PropTypes.func
};
export default UIKitContext;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment