Skip to content

Instantly share code, notes, and snippets.

View mikedklein's full-sized avatar
💻
Making BA Shit

Mike Klein mikedklein

💻
Making BA Shit
View GitHub Profile
@acdlite
acdlite / app.js
Last active January 20, 2023 08:23
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
class App extends React.Component {
render() {
return (
<Router>
{({ location }) => (
<div>
<Nav/>
<Main>
{redirects.map(redirect => <Redirect {...redirect}/>)}
{routes.map(route => <Match {...route}/>)}
@mirague
mirague / CustomComponent-test.js
Last active November 9, 2021 09:32
Testing React-Intl components with Enzyme's mount() and shallow() methods. This is a helper function which wraps the `intl` context around your component tests in an easy and efficient way.
import { mountWithIntl } from 'helpers/intl-enzyme-test-helper.js';
const wrapper = mountWithIntl(
<CustomComponent />
);
expect(wrapper.state('foo')).to.equal('bar'); // OK
expect(wrapper.text()).to.equal('Hello World!'); // OK