Skip to content

Instantly share code, notes, and snippets.

State Management:
- Immutable vs Mutable
- Lifting State & Prop Drilling vs. Context
- Derived State
- Rerendering Performance
- Plain: useState / useReducer
○ mit Immer: https://immerjs.github.io/immer/docs/introduction
○ mit Constate
import React, { useState } from 'react';
import produce from 'immer';
import logo from './logo.svg';
import './App.css';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
interface BlogData {
name: any;
change: Date;
@jbandi
jbandi / gisttools.js
Created April 8, 2018 23:37
Description of gist
export function createConnect<InjectedProps>(injectedProp: string) {
return function connect<ComponentProps>() {
type Props = ComponentProps & InjectedProps;
type Factory = (props: Props) => IReactComponent<Props>;
return (factory: Factory) => {
const fakeProps = {} as Props;
const Component = inject(injectedProp)(observer(factory(fakeProps)));
return (props: ComponentProps) => <Component {...props as Props} />;
};
};
{
"name": "starter",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.1.1",
"react-dom": "^16.1.1",
"react-scripts": "1.0.17"
},
"scripts": {
{
"name": "awesome-ng",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
(function () {
if (new window.Intl.DateTimeFormat('it-CH').format(new Date()).indexOf('.') != -1) return;
var NativeDateTimeFormat = window.Intl.DateTimeFormat;
window.Intl.DateTimeFormat = function (locale) {
//console.log('DateTimeFormat constructed', arguments);
if (!(this instanceof window.Intl.DateTimeFormat)) { // enforce constructor
throw new Error('window.Intl.DateTimeFormat not called as constructor!');
console.log(new window.Intl.DateTimeFormat('de-CH', {year:'numeric',month:'numeric',day:'numeric'}).format(new Date()));
console.log(new window.Intl.DateTimeFormat('fr-CH', {year:'numeric',month:'numeric',day:'numeric'}).format(new Date()));
console.log(new window.Intl.DateTimeFormat('it-CH', {year:'numeric',month:'numeric',day:'numeric'}).format(new Date()));
@jbandi
jbandi / date_time_ch.js
Last active July 13, 2017 22:01
Checking date time formatting for Switzerland
console.log(new window.Intl.DateTimeFormat('de-CH').format(new Date()));
console.log(new window.Intl.DateTimeFormat('fr-CH').format(new Date()));
console.log(new window.Intl.DateTimeFormat('it-CH').format(new Date()));
@jbandi
jbandi / script4.js
Created May 3, 2015 21:13
script4.js
console.log("Hello from script 4!");
@jbandi
jbandi / script1.js
Created May 3, 2015 21:07
script1.js
console.log("Hello from script 1!");