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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { compose, setPropTypes, withHandlers, lifecycle, getContext, withState } from 'recompose' | |
const HomeScene = ({ }) => ( | |
<View> | |
// omitted | |
</View> | |
) | |
export default compose( | |
setPropTypes({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { compose, withProps } from recompose | |
class RefsStore { | |
store(name, value) { | |
this[name] = value; | |
} | |
} | |
const enhance = compose( | |
withProps({ refs: new RefsStore() }), | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AsyncButton extends Component { | |
render() { | |
const { | |
loading, | |
action, | |
label, | |
children | |
} = this.props | |
return ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
class Home extends React.Component { | |
state = { Component: null } | |
componentWillMount() { | |
import('./Home').then(Component => { | |
this.setState({ Component }) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { | |
compose, | |
setDisplayName, | |
setPropTypes, | |
withState, | |
withHandlers | |
} from 'recompose' | |
const {Component} = React; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { | |
compose, | |
setDisplayName, | |
setPropTypes, | |
withState, | |
withHandlers, | |
lifecycle, | |
mapProps |