Skip to content

Instantly share code, notes, and snippets.

@gregnb
gregnb / React-Hooks-Notes
Last active February 9, 2019 22:47
React Hooks - Notes
// useState():
Note: "However, unlike this.setState in a class, updating a state variable always replaces it instead of merging it."
/* before - example 1 */
constructor(props) {
super(props);
this.state = {
count: 0
};
@gregnb
gregnb / deep-merge-object.js
Created February 8, 2018 02:43
deep merge two objects
// mergeDeep({ a: {b: 2} }, { a: { b: 5 }})
// = { a: { b: 5 }}
function mergeDeep(obj1, obj2) {
let newObj = { ...obj2 };
const recurseObj = (obj1, obj2) => {
Object.keys(obj1).forEach(key => {
if (typeof obj1[key] === "object" && obj2[key] !== undefined) {
@gregnb
gregnb / css-fadeup.html
Created June 12, 2017 21:37
CSS stagger fade up animation
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>CSS Staggered fade up effect</title>
</head>
<script type="application/javascript">
</script>
import React from 'react';
import { apiRequest, apiError, detectAndroid } from './Utils';
let FrontendComponent = ComposedComponent => {
class FrontendClass extends ComposedComponent {
constructor() {
super();
@gregnb
gregnb / webpack.config.js
Created June 5, 2017 23:36
simple webpack config
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var config = {
watchOptions: {
aggregateTimeout: 300,
poll: 1000
},
@gregnb
gregnb / es6-singly-linkedlist.js
Last active June 13, 2019 20:02
ES6 Singly Linked List
class Node {
constructor(data) {
this.next = null;
this.data = data;
}
}
class LinkedList {
constructor() {