Skip to content

Instantly share code, notes, and snippets.

@nnarhinen
nnarhinen / Products.tsx
Created February 20, 2019 06:30
React hooks + redux-hooks + redux-router-dom + immer-reducer
import React, { useEffect } from "react";
import { withRouter } from 'react-router-dom'
import { useProductSelectors, useProductActions } from "../redux/actions/products"
import Qs from 'querystring'
const Products = withRouter(({ location: { search }, history}) => {
const actions = useProductActions()
const [products] = useProductSelectors(selectors => [selectors.getProducts()])
import Raven from 'raven-js';
if (process.env.NODE_ENV === 'production') {
Raven.config('https://<foo>@app.getsentry.com/<bar>').install();
window.onunhandledrejection = function(data) {
Raven.captureException(data.reason);
};
}
const TeamForm = ({ handleSubmit, i18n, array }) => (
<form onSubmit={handleSubmit}>
{ /* Other form inputs */ }
<Field name="persons" component={renderRows(i18n)} array={array} />
{ /* Other form inputs */ }
</form>
);
@nnarhinen
nnarhinen / component.js
Last active March 15, 2016 09:46
OR validation for React props
const Component = React.createClass({
propTypes: {
file: requireThisOr('files', React.PropTypes.instanceOf(File).isRequired),
files: requireThisOr('file', React.PropTypes.arrayOf(React.PropTypes.instanceOf(File)).isRequired)
}
})
@nnarhinen
nnarhinen / app.js
Created December 30, 2015 13:19
i18n in redux react app
//omitted a lot
translations.fi().then(i18n => {
let initialState = {
locales: {
currentLocale: 'fi',
i18n
}
};
const store = am(createStore)(reducer, initialState);
@nnarhinen
nnarhinen / Makefile
Last active August 29, 2015 14:14
How to import bootstrap and react-widgets theme to your stylus file
export PATH := ./node_modules/.bin/:$(PATH)
node_modules_less_files = $(shell find node_modules -type f -name '*.less')
default.css: bootstrap.css react-widgets.css default.styl
stylus --include-css -u nib --import nib -p default.styl > $@
bootstrap.css: build-bootstrap.less $(node_modules_less_files)
lessc build-bootstrap.less > $@
react-widgets.css: build-react-widgets.less $(node_modules_less_files)
dist/application.min.js
@nnarhinen
nnarhinen / TodoActions.js
Created November 30, 2014 13:52
Reflux - handling ajax errors on creation
var Reflux = require('reflux'),
_ = require('underscore'),
api = require('./api');
var TodoActions = Reflux.createActions(['create', 'created', 'errored']);
TodoActions.create.preEmit = function(data) {
data = _.extend({_iid: _.uniqueId('todo_')}, data);
api.createTodo(data).then(function(todo) { TodoActions.created(_.extend({_iid: data._iid}, todo)); })
.catch(function(err) { TodoActions.errored(_.extend({_iid: data._iid}, {_error: err}))});
@nnarhinen
nnarhinen / README.md
Created November 29, 2014 10:33
Browserify not reading package.json?

Works:

./node_modules/.bin/browserify -t [reactify --es6] src/frontend/index.js 

Does not work:

./node_modules/.bin/browserify src/frontend.index.js
@nnarhinen
nnarhinen / openssl.js
Last active August 29, 2015 14:10
Openssl wrapper for nodejs
'use strict';
var spawn = require('child_process').spawn,
Promise = require('bluebird'),
_ = require('underscore'),
concat = require('concat-stream');
var o = module.exports = {};
o.req = function(privKeyPem, subjectData) {
return new Promise(function(resolve, reject) {