Skip to content

Instantly share code, notes, and snippets.

@maxcodes
maxcodes / HomeScene_Original.js
Last active January 21, 2018 17:48
OneSignal
import { compose, setPropTypes, withHandlers, lifecycle, getContext, withState } from 'recompose'
const HomeScene = ({ }) => (
<View>
// omitted
</View>
)
export default compose(
setPropTypes({
@busypeoples
busypeoples / README.md
Last active October 3, 2017 05:00
setSateHigherOrderComponent for combining stateless functions with setState functions on the fly.

SetState React HigherOrderComponent

Why?

If you want to write stateless functions in React and need to combine a number of setState functions to that stateless function. Enables to compose a number of functions expecting state and props. This enables to reuse functions when needed and eases testing those functions (as they are standalone and decoupled from React.

Example

@NikolaRavic
NikolaRavic / MultiSelect.js
Created July 4, 2017 11:41
React-native multi select accordion
import React, { Component } from 'react';
import { View, Text, TouchableOpacity, Animated, StyleSheet } from 'react-native';
import { AppSizes, AppColors, AppFonts } from '@theme';
import { Icon } from 'react-native-elements';
export class SelectGroup extends Component {
constructor (props) {
super(props);
this.state = {
expanded: true,
@komkanit
komkanit / refs.js
Last active January 21, 2018 17:31
import { compose, withProps } from recompose
class RefsStore {
store(name, value) {
this[name] = value;
}
}
const enhance = compose(
withProps({ refs: new RefsStore() }),
)
@benoneal
benoneal / classical.js
Last active October 3, 2017 03:18
Controlled/uncontrolled pattern with Recompose
class AsyncButton extends Component {
render() {
const {
loading,
action,
label,
children
} = this.props
return (
import { ListView } from 'react-native';
import { compose, withProps } from 'recompose';
import TransactionItem from './TransactionItem';
const withDataSource = withProps({
ds: new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 }),
});
const withClonedDataSource = withProps(({ ds, transactions = [] }) => ({
dataSource: ds.cloneWithRows(transactions),
import React from 'react'
class Home extends React.Component {
state = { Component: null }
componentWillMount() {
import('./Home').then(Component => {
this.setState({ Component })
})
}
import React from 'react';
import PropTypes from 'prop-types';
import { getContext, withContext } from 'recompose';
const Provider = () => withContext(
{ stores: PropTypes.object },
props => ({ stores: props })
)(props => React.Children.only(props.children));
@neroze
neroze / with-withState-withHandlers
Created June 20, 2017 10:11
with-withState-withHandlers
import React from 'react';
import {
compose,
setDisplayName,
setPropTypes,
withState,
withHandlers
} from 'recompose'
const {Component} = React;
import React from 'react';
import {
compose,
setDisplayName,
setPropTypes,
withState,
withHandlers,
lifecycle,
mapProps