Skip to content

Instantly share code, notes, and snippets.


Francesco Sardo frankiesardo

  • London
View GitHub Profile
View new.json
"resources": [
"id": 52524332,
"sentToSupplierAt": "2020-05-22T11:38:18.738886+01:00",
"productConfig": [{ "productId": 193589,
"title": "Whizz Floor Lamp",
"image": ""}],
"quoteId": 26518736,
"hasUnreadMessages": false,
View App.js
import React from 'react';
import './App.css';
const actionType = {
SHOW: "show",
HIDE: "hide"
function reducer(state, action) {
frankiesardo / ColocatingEffectsAndReducers.js
Last active Jul 28, 2020
Colocating effects and reducers
View ColocatingEffectsAndReducers.js
// This is an example on how to use the library
import React from 'react';
// This is the hook
function useReducerWithEffects(reducer, handlers, initialState) {
const [{ state, ...effects }, setState] = React.useState({ state: initialState })
const dispatch = React.useCallback(action => setState(({ state }) => ({ state, ...reducer(state, action) })), [reducer])
React.useEffect(function () {
View reducer-context.core.cljs
(ns reducer-context.core
(:require ["react" :as react :rename {createElement $}]
["react-dom" :as dom]
[goog.object :as obj]))
(extend-type object
([o k] (obj/get o (name k)))
([o k not-found] (obj/get o (name k) not-found))))
View wrapper.cljc
(ns react.wrapper
#?(:cljs (:require ["react" :as react]
[goog.object :as obj])))
(defn component [display-name render]
(let [f (fn [props] (apply render (obj/get props "value")))
m (react/memo f #(= (obj/get %1 "value") (obj/get %2 "value")))]
(obj/set f "displayName" display-name)
View effective-reducer.cljs
["expo" :as ex]
["react-native" :as rn]
["react" :as react :rename {createElement $}]
[shadow.expo :as expo]))
(defn useEffectiveReducer [reducer handlers initial-state]
(let [[state set-state] (react/useState initial-state)
[queue update-queue] (react/useReducer (fn [state action] (action state)) [])
frankiesardo / core.cljs
Created Feb 7, 2020
View core.cljs
(ns stop-worry.core
(:require ["react" :as react :rename {createElement $}]
["react-dom" :as dom]
[goog.object :as obj]
[cljs.core.async :as async]))
(extend-type object
([o k] (obj/get o (name k)))
View react.helper.clj
(ns react.helper)
(defmacro defc [name argv & body]
`(def ~name (react.helper/component (str '~(get-in &env [:ns :name]) "/" (name '~name)) (fn ~argv ~@body))))
View core.cljs
(ns example.core
(:require [react.helper :refer-macros [defc]]
[goog.object :as obj]))
(extend-type object
View helper.cljc
(ns react.helper
#?(:cljs (:require [cljsjs.react]
(defn- react-factory [display-name render]
#js {:displayName display-name
You can’t perform that action at this time.