Skip to content

Instantly share code, notes, and snippets.

import { useEffect, useState, useReducer } from 'react';
import { isEmpty, isNil } from 'ramda';
const isObjectLiked = (value) =>
value.constructor.name == "Array" ||
value.constructor.name == "Object";
const rehydrate = (value, defaultValue) => {
if (!value) return defaultValue;
if (value === 'false') str = false;
import React, { Component, createContext } from "react"
import { differenceBy } from "lodash/fp"
const { Provider, Consumer: MultiSelectConsumer } = createContext({})
export function toggleItemUpdater(item) {
return ({ items: currentStateItems }) => {
const hasItem = currentStateItems.some(it => it.id === item.id)
if (hasItem) {
return { items: currentStateItems.filter(it => it.id !== item.id) }
@deceive3w
deceive3w / Screen.js
Last active April 19, 2019 11:24
Fix Multiple React Native Navigation
//change Screen.js in node modules react-native-navigation
/*eslint-disable*/
import React, {Component} from 'react';
import {
NativeAppEventEmitter,
DeviceEventEmitter,
Platform
} from 'react-native';
import platformSpecific from './deprecated/platformSpecificDeprecated';
import React, { Component, createContext } from 'react';
const context = createContext({
activeTabId: '',
changeTab: () => {}
});
const { Provider, Consumer } = context;
const Tab = ({ id, children }) => (
@jatazoulja
jatazoulja / AuthContext.js
Created August 1, 2018 01:00
Context with HoC for consumer.
import React, { createContext, Component } from "react";
import { Auth } from "aws-amplify";
const AuthContext = createContext({
isAuthenticated: false,
isAuthenticating: true
});
class AuthProvider extends Component {
state = {
isAuthenticated: false,
// Below I am using react's context api to create a modular way to manage modals within an application
// Context Environment
import React, { Component, createContext } from 'react'
const ModalContext = createContext({
component: null,
props: {},
showModal: () => {},
@suhanlee
suhanlee / SlideIn.js
Created April 16, 2018 17:03
react-native-ui-animations
import React from 'react'
import PropTypes from 'prop-types';
import { Animated, Easing } from 'react-native'
class SlideIn extends React.Component {
constructor(props) {
super(props);
this.state = {
height: new Animated.Value(0),
@asmyk
asmyk / rn-simple-composed-form.js
Created March 12, 2018 11:31
React native form example with recompose
class MyForm extends Component {
render() {
let { formData, onSubmitForm } = this.props;
return (
<View>
<TextInput value={formData.name} />
<TextInput value={formData.email} />
export const createContext = value => {
const context = reactCreateContext(value);
export const withContext = Component => {
const C = props => (
<context.Consumer>
{context => <Component {...context} {...props} />}
</context.Consumer>
);
@pokorson
pokorson / components.js
Created February 6, 2018 19:22
Recompose examples
const Buttons = branch(
props => props.loading,
withProps({ label: 'LOADING...', isDisabled: true }),
withProps({ id: 'signIn', label: 'SIGN IN', type: 'submit' })
)(SignInButton);
const Buttons = ({ loading }) =>
loading ? (
<SignInButton label="LOADING..." isDisabled={true} />
) : (