Skip to content

Instantly share code, notes, and snippets.

View williamtran29's full-sized avatar
🏠
Working from home

William Tran williamtran29

🏠
Working from home
  • Freelancer
  • Silicon Valley
View GitHub Profile
import React from 'react';
import User from './User';
import { connect } from 'react-redux';
import { fetchUsers } from '../actions/index';
import { lifecycle, compose } from 'recompose';
const enhance = compose(
lifecycle({
componentDidMount() {
this.props.fetchUsers();
@williamtran29
williamtran29 / App.js
Created June 29, 2017 12:17 — forked from knowbody/App.js
Check internet connection in React Native app
// quick snippet to check the connection in your RN app
// dispatches an `setIsConnected` action every time the NetInfo changes (on/off network)
componentDidMount() {
const dispatchConnected = isConnected => this.props.dispatch(setIsConnected(isConnected));
NetInfo.isConnected.fetch().then().done(() => {
NetInfo.isConnected.addEventListener('change', dispatchConnected);
});
}
@williamtran29
williamtran29 / FadeIn.js
Last active April 25, 2017 10:56
Create FadeIn Animation for any React Native Component
/* @flow */
import React, { Component, PropTypes } from 'react'
import {
Animated
} from 'react-native'
export default class FadeIn extends Component {
static propTypes = {
children: PropTypes.node,
@williamtran29
williamtran29 / SectionListView.js
Last active September 15, 2020 21:13
[React Native ListView] Scroll to a section by a sectionId, Scroll to a row by a rowId, Receive callbacks when a section changes, Pinned Section and more...
import React, {
Component,
PropTypes
} from 'react'
import {
ListView
} from 'react-native'
// arbitrarily large distance to pre-render all sections for measurements
const RENDER_AHEAD_DISTANCE = 1000000