Skip to content

Instantly share code, notes, and snippets.

View sriramrudraraju's full-sized avatar

Sriram Rudraraju sriramrudraraju

  • Bentonville, AR
View GitHub Profile
@sriramrudraraju
sriramrudraraju / app.js
Last active August 2, 2017 18:35 — forked from acdlite/app.js
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 => {
@sriramrudraraju
sriramrudraraju / React-Redux-Unit-Testing-Part-1.md
Last active November 2, 2017 16:49
React Redux Unit Testing with Jest part 1: Action Creators

React Redux Unit Testing: Part 1

Example for Action Creators using jest

Thanks to Max Stoiber for his blog on regular actions

Thanks to Ferran Negre for his blog on async actions

@sriramrudraraju
sriramrudraraju / React-Redux-Unit-Testing-Part-2.md
Last active November 2, 2017 16:48
React Redux Unit Testing with Jest part 2: Reducers

React Redux Unit Testing: Part 2

Example for Reducers using jest

Thanks to Max Stoiber for his blog

@sriramrudraraju
sriramrudraraju / React-Redux-Unit-Testing-Part-3.md
Last active November 2, 2017 16:47
React Redux Unit Testing with Jest part 3: Components

React Redux Unit Testing: Part 3

Example for Components using jest

Thanks to Max Stoiber for his blog

>Note: I didnt get as successfull snapshot as followed from blog. So I tweaked it to make it work

@sriramrudraraju
sriramrudraraju / React-Redux-Unit-Tests.md
Last active November 11, 2023 02:00
React Redux Unit Tests: Full App
@sriramrudraraju
sriramrudraraju / Express-Seed-Project.md
Last active November 2, 2017 16:51
Creating Express Js seed project
@sriramrudraraju
sriramrudraraju / create-react-app-webpack-prod.md
Last active April 8, 2021 02:20
Optimizing production build create-react-app using svg-url-loader

Create-React-App Production build Optimizataion

Svg-Url-Loader

Requirement

Instead moving .svg files from src/assets/ to build/static/media/ during npm run build. .svg files have to be bundled into build/static/js/main.js

Steps

@sriramrudraraju
sriramrudraraju / lozad-image-wrapper.tsx
Created August 22, 2018 20:30
lazy loading images in react
// React wrapper for lozad.js for images
import * as React from 'react';
import * as lozad from 'lozad';
// src: the image path that will be lazyloaded
// customClass: css class that will be applied to img element
// defaultImageSrc: image path (preferebly local to this app) that needs to be displayed
// by default before the required imgae lazy loaded
interface LozadWrapperProps {
@sriramrudraraju
sriramrudraraju / Readme.md
Last active September 10, 2018 14:23
Responsive Placeholder Image

Transparent responsive data uri

data:image/svg+xml;charset=utf-8,%3Csvg xmlns%3D"http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" viewBox%3D"0 0 228.5 127.22"%2F%3E

  • 228.5 represents width
  • 127.22 respresents height
  • height and width preserve aspect ratio.
  • more info