Skip to content

Instantly share code, notes, and snippets.

Avatar

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
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
ILookup
(-lookup
([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])))
#?(:cljs
(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
(ns example.app
(:require
["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
frankiesardo / core.cljs
Created Feb 7, 2020
stop.worry/love-js
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
ILookup
(-lookup
([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]]
[cljsjs.react.dom]
[goog.object :as obj]))
(enable-console-print!)
(extend-type object
ILookup
(-lookup
View helper.cljc
(ns react.helper
#?(:cljs (:require [cljsjs.react]
[cljsjs.create-react-class])))
#?(:cljs
(defn- react-factory [display-name render]
(js/React.createFactory
(js/createReactClass
#js {:displayName display-name
:shouldComponentUpdate
You can’t perform that action at this time.