Skip to content

Instantly share code, notes, and snippets.

View jamesgpearce's full-sized avatar
Always hacking somewhere

James Pearce jamesgpearce

Always hacking somewhere
View GitHub Profile
@jamesgpearce
jamesgpearce / App.js
Last active September 10, 2024 18:57
Modified version of TinyBase Expo example to demonstrate synchronization. This updates https://github.com/expo/examples/tree/master/with-tinybase
import { useCallback, useState } from 'react';
import * as SQLite from 'expo-sqlite';
import {
FlatList,
Platform,
StyleSheet,
Text,
TextInput,
TouchableOpacity,
} from 'react-native';
@jamesgpearce
jamesgpearce / dimoc.md
Last active September 22, 2017 23:34
DIMOC: Do It Myself or Callback - a simple pattern for React components

TLDR: a React component should either manage its own state, or expose a callback so that its parent can. But never both.

Sometimes our first impulse is for a component to entirely manage its own state. Consider this simple theater seating picker that has a letter for a row, and a number for a seat. Clicking the buttons to increment each value is hardly the height of user-interface design, but never mind - that's how it works:

/* @flow */
var React = require('react');

var Letter: React.ReactClass = React.createClass({
  getInitialState: function(): any {