Skip to content

Instantly share code, notes, and snippets.

@brandondurham
Last active May 28, 2017 21:04
Show Gist options
  • Save brandondurham/39e81ac1d0368b6a3ce2660c3dc230f6 to your computer and use it in GitHub Desktop.
Save brandondurham/39e81ac1d0368b6a3ce2660c3dc230f6 to your computer and use it in GitHub Desktop.
Higher-order component to ensure all static, same-domain links loaded from external sources use the router method
// To use with your component as a decorator:
import React from 'react';
import styles from './styles.css';
import Internalize from 'components/InternalLinks';
@Internalize
export default class BlogContent extends React.Component {
static propTypes = {
content: PropTypes.static.isRequired
};
render() {
const { content } = this.props;
return (
<article className={ styles.containerClassName }>
{ content }
</article>
);
}
}
// As a higher-order component:
import React from 'react';
import styles from './styles.css';
import Internalize from 'components/InternalLinks';
export class BlogContent extends React.Component {
static propTypes = {
content: PropTypes.static.isRequired
};
render() {
const { content } = this.props;
return (
<article className={ styles.containerClassName }>
{ content }
</article>
);
}
}
export default Internalize(BlogContent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment