Skip to content

Instantly share code, notes, and snippets.

View rickbeerendonk's full-sized avatar
🎯
Focusing

Rick Beerendonk rickbeerendonk

🎯
Focusing
View GitHub Profile
@JeremyJonas
JeremyJonas / with-time.jsx
Last active February 11, 2020 13:47
React HOC Timer - provide wrapped component with `time` prop at given interval
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { omit } from 'lodash'
class Timer extends PureComponent {
static get propTypes () {
return {
Component: PropTypes.func.isRequired,
interval: PropTypes.number,
innerRef: PropTypes.func
@wmertens
wmertens / router.jsx
Last active August 10, 2017 11:14
Wrapper for react-router v4 with an API more to my tastes
import React, {Component, PropTypes} from 'react'
import {Link, Route as OrigRoute, Switch, Redirect, BrowserRouter as Router, withRouter} from 'react-router-dom'
// Subscribes a child to history updates, passing the current location as a prop
// This is needed to work around the React context API not updating all children
// See https://github.com/ReactTraining/react-router/issues/4629#issuecomment-284218493
export class LocationListener extends Component {
static contextTypes = {
history: PropTypes.object,
}
@borkdude
borkdude / planck-dependency.md
Last active August 4, 2016 02:12
Fast REPL session with a cljs library using Planck

Get a fast starting REPL session with a ClojureScript library using Planck.

This is a draft of what will be eventually a blog post. Feedback is welcome.

It started by asking this question on StackOverflow. A good answer turned out to be Planck. This is how you solve it with Planck.

First, decide what dependencies Planck needs to load. This is easily done with boot like this:

$ boot --dependencies org.clojars.micha/boot-cp        ; load with-cp task that helps exporting minimal classpath to file

--dependencies com.andrewmcveigh/cljs-time:"0.4.0" ; load dependency you actually want to try

@markerikson
markerikson / redux-timer-middleware.js
Last active January 5, 2021 17:37
Sample Redux timer middleware
function timerMiddleware({dispatch, getState}) {
const timers = {};
return next => action => {
if(action.type == "START_TIMER") {
const {action, timerName, timerInterval} = action.payload;
clearInterval(timers[timerName]);
// Have some complicated non-React widgets that manipulate DOM?
// Do they manage a list of DOM elements? Here's how to wrap it
// into a React component so you can "constantly rerender" it.
// A dumb non-react widget that manually manage some DOM node that
// represent a list of items
function NonReactWidget(node) {
this.node = node;
}
@sebmarkbage
sebmarkbage / react-terminology.md
Last active January 9, 2023 22:47
React (Virtual) DOM Terminology
@nrn
nrn / react-internals.md
Last active April 1, 2018 18:02
Notes for react internals discussion.

react internals discussion

React: a robust functional view layer.

View code and templating are combined as JavaScript.

In JavaScript you create a virtual DOM, react diffs changes between the last virtual DOM and the next, mutating the real DOM only as necessary to reflect the changes. This has huge implications for cognitive

@sebmarkbage
sebmarkbage / ElementFactoriesAndJSX.md
Last active May 17, 2022 11:06
New React Element Factories and JSX

New React Element Factories and JSX

In React 0.12, we're making a core change to how React.createClass(...) and JSX works.

If you're using JSX in the typical way for all (and only) React components, then this transition will be seamless. Otherwise there are some minor breaking changes described below.

The Problem

; Comments start with semicolons.
; Clojure is written in "forms", which are just
; lists of things inside parentheses, separated by whitespace.
;
; The clojure reader assumes that the first thing is a
; function or macro to call, and the rest are arguments.
;
; Here's a function that sets the current namespace:
(ns test)
@fogus
fogus / hocs.clj
Created November 20, 2012 16:47
core.contracts with HoCs
(def C
(contract
foo
"bar"
[f n]
[(integer? n)
(_ f [n] [odd?])
=>
integer?]))