Skip to content

Instantly share code, notes, and snippets.

@jtibbertsma
jtibbertsma / actions.js
Last active December 28, 2020 06:23
react-native-navigation redux middleware example
import { createAction } from 'redux-actions';
import {
NAVIGATION_PUSH,
NAVIGATION_POP,
NAVIGATION_RESET_TO,
NAVIGATION_POP_TO_ROOT
} from './actions';
export const push = createAction(NAVIGATION_PUSH);
export const pop = createAction(NAVIGATION_POP);
@jwo
jwo / map.js
Last active March 31, 2022 10:41
React google maps with multiple markers, only one info window
import React, { Component } from "react"
import { compose } from "recompose"
import {
withScriptjs,
withGoogleMap,
GoogleMap,
Marker,
InfoWindow
} from "react-google-maps"
@dangh
dangh / hoc-component.jsx
Last active October 3, 2017 03:25
Recompose as HoC and render prop
import { compose, withState, withProps } from 'recompose'
function HoCComponent ({a, b, c, setA, setB}) {
return (
<div>
<span>A: {a}</span>
<button onClick={setA}>Update A</button>
<span>B: {b}</span>
<button onClick={setB}>Update B</button>
<span>C: {c}</span>
import _ from "lodash";
import { graphql } from "react-apollo";
import { compose, setDisplayName, wrapDisplayName } from "recompose";
const isServer = typeof window !== "object";
const DEFAULT_OPTIONS = {
fetchPolicy: isServer ? "network-first" : "cache-and-network"
};
@juliensanmartin
juliensanmartin / map.component.js
Last active October 4, 2017 07:20
Dumb component displaying a map. It's a bit heavy and need to get cleaned but it's functionnal
import {
StyleSheet,
View,
TouchableOpacity
} from 'react-native'
import { Icon } from 'react-native-elements'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import MapView, { PROVIDER_GOOGLE } from 'react-native-maps'
import styled from 'styled-components/native'
@hubgit
hubgit / ConnectPage.js
Created August 30, 2017 21:25
ConnectPage HOC for async actions that must be completed before rendering
import React from 'react'
import { compose } from 'recompose'
import { connect } from 'react-redux'
import { withRouter } from 'react-router'
import classes from './ConnectPage.local.css'
const ConnectPage = requirements => WrappedComponent => {
class ConnectedComponent extends React.Component {
state = {
fetching: false,
@deadcoder0904
deadcoder0904 / eslintrc.md
Last active October 14, 2017 09:51
ESLINT CONFIG

Step 1 : Install eslint & babel-eslint

yarn add eslint babel-eslint -D

Step 2 : Start setup

./node_modules/.bin/eslint --init

Step 3 : Add the following to .eslintrc.json

// Tweet.js
import React from 'react';
import { compose, flattenProp, onlyUpdateForKeys } from 'recompose';
const enhance = compose(
flattenProp('tweet'),
flattenProp('user'),
onlyUpdateForKeys(['username', 'image', 'name', 'tweet']),
);
@dumpsayamrat
dumpsayamrat / TweetBox-2.js
Last active October 3, 2017 04:07
TweetHome-2
// TweetBox.js
import React from 'react';
import { compose, mapProps, flattenProp } from 'recompose';
const enhance = compose(
mapProps(({ limit, message, ...rest }) => ({
...rest,
limit,
message,
textRemaining: limit - message.length
import React, {Component} from "react";
import {Animated, Dimensions, Platform, Text, View} from 'react-native';
import {Body, Header, List, ListItem as Item, ScrollableTab, Tab, Tabs, Title} from "native-base";
const NAVBAR_HEIGHT = 56;
const {width: SCREEN_WIDTH} = Dimensions.get("window");
const COLOR = "rgb(45,181,102)";
const TAB_PROPS = {
tabStyle: {width: SCREEN_WIDTH / 2, backgroundColor: COLOR},
activeTabStyle: {width: SCREEN_WIDTH / 2, backgroundColor: COLOR},