Skip to content

Instantly share code, notes, and snippets.

I was looking for a better way to compose multiple render prop based components. https://codesandbox.io/s/pm04m73n2x

const h = React.createElement;

const id = x => x;

const basicRenderCb = (result, Next) => // Next is the next component in the list.
 h(Next, result);
var objectForeach = require("object-foreach");
// list of keys to make the tree structure map
const store = {
optimist: [],
entities: {
users: {}
}
};
@tkh44
tkh44 / reset-styles.js
Created September 27, 2017 05:50
glamor reset for emotion
import { injectGlobal } from 'react-emotion';
/*! normalize.css v5.0.0 | MIT License | github.com/necolas/normalize.css */
/**
* 1. Change the default font family in all browsers (opinionated).
* 2. Correct the line height in all browsers.
* 3. Prevent adjustments of font size after orientation changes in
* IE on Windows Phone and in iOS.
*/
@tkh44
tkh44 / index.js
Last active September 17, 2017 02:28 — forked from VictorCoding/index.js
working with search/filtering items
import React from 'react'
import { Div } from 'glamorous'
const filterPosts = (posts, term) => posts.filter(item => item.includes(term))
function List({ items }) {
return <ul>{items.map((p, i) => <li key={i}>{p}</li>)}</ul>
}
class Index extends React.Component {
@tkh44
tkh44 / class-property-method.js
Last active September 16, 2017 17:02
Brainstorming some high performance alternatives to using styled with emotion. Bonus glamor version.
import { css } from 'emotion'
class Profile extends Component {
css = (p) => css`
color: blue;
height: ${p.parentHeight};
`
render() {
return (<div className={this.css(props)}/>)
}
@tkh44
tkh44 / Insights.js
Last active September 13, 2022 01:24
import { Component } from 'react'
import { get } from 'lodash'
import { connect } from 'react-redux'
import compose from 'recompose/compose'
import roomLoader from 'room/room-loader'
import { Request, Subscribe } from 'react-nes'
import { css, StyleSheet } from 'aphrodite/no-important'
import { breakpoints, colors, font, mediaQueries } from 'style'
import Header from 'ui/Header'
import Footer from 'ui/Footer'
@tkh44
tkh44 / Box.js
Created August 30, 2017 20:54
styled-system with emotion.
import styled, { css } from 'emotion/react'
import { space, width, fontSize, color, responsiveStyle } from 'styled-system'
export const display = responsiveStyle('display')
export const flex = responsiveStyle('flex')
export const order = responsiveStyle('order')
const wrap = responsiveStyle('flex-wrap', 'wrap', 'wrap')
const direction = responsiveStyle('flexDirection', 'direction')
const align = responsiveStyle('alignItems', 'align')
@tkh44
tkh44 / index.js
Created August 25, 2017 19:25
Getting react-leaflet working with SSR (next.js)
import React from 'react'
export default class extends React.Component {
constructor () {
super()
this.state = { components: undefined }
this.markers = new WeakMap()
}
componentDidMount () {
import React from 'react';
import { findDOMNode } from 'react-dom';
import PropTypes from 'prop-types';
import listen from 'simple-listen';
import { getTop } from 'fbjs/lib/Scroll';
export default class SidebarAdManager extends React.Component {
constructor (props) {
super(props);
this.state = { stickyAd: {} };
@tkh44
tkh44 / place.js
Created August 22, 2017 22:10
animating a modal with data-driven-motion
import React from 'react'
import styled from 'emotion/react'
import { Motion } from 'data-driven-motion'
import theme from '../../lib/theme'
import Place from '../place'
const Backdrop = styled.div`
position: fixed;
left: 0;