Skip to content

Instantly share code, notes, and snippets.

Niklas Närhinen nnarhinen

Block or report user

Report or block nnarhinen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nnarhinen
nnarhinen / Products.tsx
Created Feb 20, 2019
React hooks + redux-hooks + redux-router-dom + immer-reducer
View Products.tsx
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()])
View index.js
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);
};
}
View team.js
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 Mar 15, 2016
OR validation for React props
View component.js
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 Dec 30, 2015
i18n in redux react app
View app.js
//omitted a lot
translations.fi().then(i18n => {
let initialState = {
locales: {
currentLocale: 'fi',
i18n
}
};
const store = am(createStore)(reducer, initialState);
@nnarhinen
nnarhinen / Makefile
Last active Aug 29, 2015
How to import bootstrap and react-widgets theme to your stylus file
View Makefile
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)
@nnarhinen
nnarhinen / TodoActions.js
Created Nov 30, 2014
Reflux - handling ajax errors on creation
View TodoActions.js
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 Nov 29, 2014
Browserify not reading package.json?
View README.md

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 Aug 29, 2015
Openssl wrapper for nodejs
View openssl.js
'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) {
You can’t perform that action at this time.