Skip to content

Instantly share code, notes, and snippets.

View davidfurlong's full-sized avatar
👨‍💻

David Furlong davidfurlong

👨‍💻
View GitHub Profile
@davidfurlong
davidfurlong / RoutedTabs.js
Created June 1, 2018 10:31
Ant design + RR4 Routed Tabs
import React from 'react';
import { Tabs } from 'antd';
import PropTypes from 'prop-types';
import { withRouter } from 'react-router-dom';
const propTypes = {
history: PropTypes.any,
location: PropTypes.any,
action: PropTypes.oneOf(['push', 'replace']).isRequired,
@davidfurlong
davidfurlong / RedirectExact.js
Created January 24, 2018 09:58
React-router 4 Exact redirect
// React-router 4 doesn't support 'exact' redirects. Very annoying. This fixes that.
import React from 'react';
import { Route, Redirect } from 'react-router-dom';
const RedirectExact = ({ from, to }) => (
<Route exact path={from} render={() => (
<Redirect from={from} to={to} />
)} />
);
@davidfurlong
davidfurlong / withPageDimensions.js
Created January 17, 2018 10:20
withPageDimensions HOC React
import React from 'react';
const withPageDimensions = WrappedComponent =>
class PageDimensions extends React.Component {
constructor(props) {
super(props);
this.state = {
width: 0,
height: 0
};
@davidfurlong
davidfurlong / package.json
Last active January 15, 2018 15:59 — forked from ricardograca/package.json
Bookshelf bug - belongsToMany and fetchAll
{
"name": "bookshelf-bug",
"version": "0.1.0",
"dependencies": {
"bookshelf": "*",
"bluebird": "*",
"knex": "*",
"sqlite3": "*"
}
}
@davidfurlong
davidfurlong / RoutedTabs.js
Last active January 8, 2018 14:35
Ant design + react-router v3 - Tabs with routes.
import React from 'react';
import { Tabs } from 'antd';
import PropTypes from 'prop-types';
import { browserHistory } from 'react-router';
function isLeftClickEvent(event) {
return event.button === 0;
}
function isModifiedEvent(event) {

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@davidfurlong
davidfurlong / JSON.stringify-replacer-sort-keys.js
Last active May 5, 2024 06:00
JSON.stringify replacer function for having object keys sorted in output (supports deeply nested objects)
// Spec http://www.ecma-international.org/ecma-262/6.0/#sec-json.stringify
const replacer = (key, value) =>
value instanceof Object && !(value instanceof Array) ?
Object.keys(value)
.sort()
.reduce((sorted, key) => {
sorted[key] = value[key];
return sorted
}, {}) :
value;
@davidfurlong
davidfurlong / conditional_js_property.js
Created April 17, 2017 07:34
Conditional js property
const _ = (obj, cond = (val) => typeof val === 'undefined' || val === null) =>
Object.assign({},
...(Object.keys(obj).map(key =>
cond(obj[key]) ? {} : {
[key]: obj[key]
})
)
);
/*
@davidfurlong
davidfurlong / statelessHOCwithContext.js
Created March 26, 2017 12:57
React HOC which returns a Stateless Functional component which has contextTypes or defaultProps or propTypes
/* its not immediately obvious how to do this, which is why I've added it here */
const connectSubmitButton = (WrappedComponent) => {
const connectContext = (props, context) => (<WrappedComponent {...props} _reduxForm={context._reduxForm} />);
connectContext.contextTypes = {
_reduxForm: PropTypes.object.isRequired
};
return connectContext;
};
@davidfurlong
davidfurlong / disableSSR.js
Last active March 16, 2017 14:25
disable server side rendering for a react component [hacky]
/*
A react higher order component (HOC) for disabling server side rendering (SSR) for a particular component.
Useful if a particular library / page doesn't support SSR and you
a) dont want to mess around with the server routing to handle it
b) dont want to the component to even be constructed on the server
c) dont want to modify the component's methods to handle loading the library on the client
(for example, you need to use window/client methods in the constructor)
DISCLAIMER: this is hacky, and will throw a console warning (in development) that the checksum is invalid (which means server & client rendering dont agree on HTML string)