Skip to content

Instantly share code, notes, and snippets.

@avinmathew
avinmathew / index.jsx
Created August 8, 2017 11:54
Multiple layouts with React Router v4
import React from "react"
import { Route, Switch } from "react-router-dom"
const AppRoute = ({ component: Component, layout: Layout, ...rest }) => (
<Route {...rest} render={props => (
<Layout>
<Component {...props} />
</Layout>
)} />
)
@madcoda
madcoda / App.js
Created May 28, 2017 04:24
React-router v4 multi layout
import React, { Component } from 'react'
import { BrowserRouter as Router, Route, Link, Match, Redirect, Switch } from 'react-router-dom'
import OverviewPage from './page/OverviewPage'
import AccountPage from './page/AccountPage'
/*
Layouts, inline define here for demo purpose
you may want to define in another file instead
*/
@patjun
patjun / gtm-ajaxsuccess-eventlistener.js
Last active May 23, 2023 17:51
GTM ajaxSuccess event listener
<script>
(function($) {
$(document).ajaxSuccess(function( event, xhr, settings ) {
dataLayer.push({
'event': 'ajaxSuccess',
'eventCategory': 'AJAX',
'eventAction': settings.url,
'eventLabel': xhr.responseText
});
});
@abury
abury / routes.js
Last active February 21, 2018 03:41
PlainRoute example with require auth for React-redux
// We only need to import the modules necessary for initial render
import CoreLayout from '../layouts/CoreLayout/CoreLayout';
import Home from './Home';
import LoginRoute from './Login';
import SignupRoute from './Signup';
import DashboardRoute from './Secure/Dashboard';
import LeadsRoute from './Secure/Leads';
import NotFound from './NotFound';
/* Note: Instead of using JSX, we recommend using react-router
@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 => {
@markerikson
markerikson / redux-timer-middleware.js
Last active January 5, 2021 17:37
Sample Redux timer middleware
function timerMiddleware({dispatch, getState}) {
const timers = {};
return next => action => {
if(action.type == "START_TIMER") {
const {action, timerName, timerInterval} = action.payload;
clearInterval(timers[timerName]);

Folder Structure

Please note

While this gist has been shared and followed for years, I regret not giving more background. It was originally a gist for the engineering org I was in, not a "general suggestion" for any React app.

Typically I avoid folders altogether. Heck, I even avoid new files. If I can build an app with one 2000 line file I will. New files and folders are a pain.

.
├── actions
├── stores
├── views
│   ├── Anonymous
│   │   ├── __tests__
│   │   ├── views
│   │   │   ├── Home
│   │   │   │   ├── __tests__
│   │   │   │   └── Handler.js
/* The Grid ---------------------- */
.lt-ie9 .row { width: 940px; max-width: 100%; min-width: 768px; margin: 0 auto; }
.lt-ie9 .row .row { width: auto; max-width: none; min-width: 0; margin: 0 -15px; }
.lt-ie9 .row.large-collapse .column,
.lt-ie9 .row.large-collapse .columns { padding: 0; }
.lt-ie9 .row .row { width: auto; max-width: none; min-width: 0; margin: 0 -15px; }
.lt-ie9 .row .row.large-collapse { margin: 0; }
.lt-ie9 .column, .lt-ie9 .columns { float: left; min-height: 1px; padding: 0 15px; position: relative; }
.lt-ie9 .column.large-centered, .columns.large-centered { float: none; margin: 0 auto; }