Skip to content

Instantly share code, notes, and snippets.

View mohandere's full-sized avatar
🎯
Focusing

Mohan Dere mohandere

🎯
Focusing
View GitHub Profile
@mohandere
mohandere / App.js
Created May 30, 2018 10:50
App.js - Obfuscate CSS class names in Create React App without eject
// File - src/App.js
import React, { Component } from 'react';
import logo from './logo.svg';
import Link from './Link';
import styles from './App.css';
class App extends Component {
render() {
return (
<div className={styles.App}>
@mohandere
mohandere / config-overrides.js
Created May 30, 2018 10:51
config-overrides.js - Obfuscate CSS class names in Create React App without eject
// File - src/config-overrides.js
// react-app-rewired: Override create-react-app webpack configs without ejecting
const path = require("path");
const { compose, getLoader, injectBabelPlugin } = require("react-app-rewired");
function rewire(config, env) {
const cssRules = getLoader(
@mohandere
mohandere / package.json
Created May 30, 2018 10:51
package.json - Obfuscate CSS class names in Create React App without eject
{
"name": "my-react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"babel-plugin-react-css-modules": "^3.4.2",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-scripts": "1.1.4"
},
@mohandere
mohandere / registerServiceWorker.js
Created August 10, 2018 16:27
Service worker working example
// Main service worker controller
function ServiceWorkerController() {
this._toastsView = new ToastsView();
this._register();
};
ServiceWorkerController.prototype._register = function() {
if (!navigator.serviceWorker) return;
var ServiceWorkerController = this;
var swUrl = "/${optportalName}/service-worker/service-worker.js";
@mohandere
mohandere / sortObject.js
Last active December 20, 2018 13:59
Sort plain js object based on custom order from Array
// Example -
// { category: 'Cloths', 'brand': 'Van H', collection: 'New' }.sortObject(['brand', 'category', 'collection']);
var sortingBasedOnArr = ['collection', 'brand', 'category'];
var targetObject = { category: 'Cloths', 'brand': 'Van H', collection: 'New' }
Object.prototype.sortObject = function(sortingArr) {
var targetObj = this;
var result = {}
if (!targetObj) {
return result;
@mohandere
mohandere / hoc-signature.js
Last active May 4, 2019 11:24
Higher-Order Components
import React from 'react'
const higherOrderComponent = WrappedComponent => {
class HOC extends React.Component {
render() {
return <WrappedComponent />
}
}
return HOC
}
@mohandere
mohandere / hoc-hof.js
Created May 4, 2019 11:25
Higher-Order Components
// Example #1
const twice = (f, v) => f(f(v))
const add3 = v => v + 3
twice(add3, 7) // 13
// Example #2
const filter = (predicate, xs) => xs.filter(predicate)
const is = type => x => Object(x) instanceof type
@mohandere
mohandere / hoc-withSearch-full-example.js
Last active May 12, 2019 14:26
Higher-Order Components
const ProductCard = props => {
return (
<div>
<hr />
<p>
<b>Title:</b> {props.title}
</p>
<p>
<b>Style:</b> {props.style}
</p>
@mohandere
mohandere / hoc-ppHOC.js
Last active May 7, 2019 14:21
Higher Order Components
const propsProxyHOC = (WraapperComponent) => {
return class extends React.Component {
state = {
count: 0
}
render() {
// Pass thru the props that the HOC receives
return <WraapperComponent {...this.props} {...this.state} />
}
}
const ProductCard = props => {
return (
<div className="product">
<p>
<b>Title:</b> {props.title}
</p>
<p>
<b>Style:</b> {props.style}
</p>
<p>