Skip to content

Instantly share code, notes, and snippets.

Avatar

Nessim Btesh nesbtesh

  • Boston
View GitHub Profile
View App.jsx
const App = ({ routes, initialData, initialToken, menus }) => (
<Switch>
{routes.map((route, index) => {
// pass in the initialData from the server or window.DATA for this
// specific route
return (
<Route
key={index}
path={route.path}
View MainTemplate.jsx
import React from 'react';
import Header from "../components/Header"
import Footer from "../components/Footer"
import LanguageChanger from "../components/LanguageChanger/index"
import { LangContext } from "../context"
class MainTemplate extends React.Component {
constructor(props) {
super(props);
View SomethingView.js
export default class SomethingView extends BaseTemplate {
// You can always overide the other class functions
renderFooter() {
return (
<div>
...coool footer
</div>
);
}
View BaseTemplate.js
export default class BaseTemplate extends React.Component {
setValue = (e) => {
const obj = {};
obj[e.target.name] = e.target.value;
this.setState(obj);
}
someOtherGlobalFunction() {
.....
}
View Galaxy.js
import React from "react";
import * as d3 from "d3";
import Tooltip from "./Tooltip"
import Icon from "./Icon"
import Spinner from "./Spinner2"
import Network from "./galaxy/Network"
var simulation;
export default class Galaxy extends React.Component {
View Network.js
import React from "react";
import * as d3 from "d3";
var simulation;
var svg;
export default class Network extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
return false;
}
@nesbtesh
nesbtesh / BadComponent.js
Created Feb 24, 2017
BAD EXAMPLE DONT USE THIS
View BadComponent.js
import React from "react";
import * as d3 from "d3";
import Tooltip from "./Tooltip"
import Icon from "./Icon"
import Spinner from "./Spinner2"
import Network from "./galaxy/Network"
var simulation;
var svg;
export default class Galaxy extends React.Component {
View AuthContainer.js
import React from "react";
import {connect} from "react-redux";
import {bindActionCreators} from "redux";
import { push, replace } from "react-router-redux";
class AuthContainer extends React.Component {
componentWillReceiveProps(nextProps) {
this.isAuthenticated();
}
View actions.js
import { checkHttpStatus, parseJSON } from '../utils';
import {LOGIN_USER_REQUEST, LOGIN_USER_FAILURE, LOGIN_USER_SUCCESS, LOGOUT_USER, FETCH_PROTECTED_DATA_REQUEST, RECEIVE_PROTECTED_DATA} from '../constants';
import { pushState } from 'redux-router';
import jwtDecode from 'jwt-decode';
export function loginUserSuccess(token) {
localStorage.setItem('token', token);
return {
type: LOGIN_USER_SUCCESS,
payload: {
View AuthReducer.js
import {createReducer} from '../utils';
import {LOGIN_USER_REQUEST, LOGIN_USER_SUCCESS, LOGIN_USER_FAILURE, LOGOUT_USER} from '../constants';
import {pushState} from 'redux-router';
import jwtDecode from 'jwt-decode';
const initialState = {
token: null,
userName: null,
isAuthenticated: false,
isAuthenticating: false,