Upgrade to Pro — share decks privately, control downloads, hide ads and more …

React Native - Thinking Offline

djirdehh
August 22, 2017

React Native - Thinking Offline

A highlight on building React Native applications with an offline first pattern as presented on both the August 2017 Toronto React Meetup and DevTO's November 2017 Meetup.

djirdehh

August 22, 2017
Tweet

More Decks by djirdehh

Other Decks in Technology

Transcript

  1. class TitleComponent extends Component { async componentDidMount() { const title

    = await AsyncStorage.getItem("title"); this.setState({ title }); } render() { const { title } = this.state; return ( <View style={styles.container}> <Text> {title} </Text> <TextInput onChangeText={this.persistTitle} /> </View> ); } persistTitle = async title => { await AsyncStorage.setItem(“title”, title); this.setState({ title }); }; } class TitleComponent extends Component { async componentDidMount() { const title = await AsyncStorage.getItem("title"); this.setState({ title }); } render() { const { title } = this.state; return ( <View style={styles.container}> <Text> {title} </Text> <TextInput onChangeText={this.persistTitle} /> </View> ); } persistTitle = async title => { await AsyncStorage.setItem("title", title); this.setState({ title }); }; } async componentDidMount() { const title = await AsyncStorage.getItem("title"); this.setState({ title }); } render() { const { title } = this.state; return ( <View style={styles.container}> <Text> {title} </Text> <TextInput onChangeText={this.persistTitle} /> </View> ); } persistTitle = async title => { await AsyncStorage.setItem("title", title); this.setState({ title }); };
  2. class TitleComponent extends Component { async componentDidMount() { const title

    = await AsyncStorage.getItem("title"); this.setState({ title }); } render() { const { title } = this.state; return ( <View style={styles.container}> <Text> {title} </Text> <TextInput onChangeText={this.persistTitle} /> </View> ); } persistTitle = async title => { await AsyncStorage.setItem(“title”, title); this.setState({ title }); }; } async componentDidMount() { const title = await AsyncStorage.getItem("title"); this.setState({ title }); }
  3. class TitleComponent extends Component { async componentDidMount() { const title

    = await AsyncStorage.getItem("title"); this.setState({ title }); } render() { const { title } = this.state; return ( <View style={styles.container}> <Text> {title} </Text> <TextInput onChangeText={this.persistTitle} /> </View> ); } persistTitle = async title => { await AsyncStorage.setItem(“title”, title); this.setState({ title }); }; } render() { const { title } = this.state; return ( <View style={styles.container}> <Text> {title} </Text> <TextInput onChangeText={this.persistTitle} /> </View> ); }
  4. class TitleComponent extends Component { async componentDidMount() { const title

    = await AsyncStorage.getItem("title"); this.setState({ title }); } render() { const { title } = this.state; return ( <View style={styles.container}> <Text> {title} </Text> <TextInput onChangeText={this.persistTitle} /> </View> ); } persistTitle = async title => { await AsyncStorage.setItem(“title”, title); this.setState({ title }); }; } persistTitle = async title => { await AsyncStorage.setItem("title", title); this.setState({ title }); };
  5. class TitleComponent extends Component { async componentDidMount() { const title

    = await AsyncStorage.getItem("title"); this.setState({ title }); } render() { const { title } = this.state; return ( <View style={styles.container}> <Text> {title} </Text> <TextInput onChangeText={this.persistTitle} /> </View> ); } persistTitle = async title => { await AsyncStorage.setItem(“title”, title); this.setState({ title }); }; } class TitleComponent extends Component { async componentDidMount() { const title = await AsyncStorage.getItem("title"); this.setState({ title }); } render() { const { title } = this.state; return ( <View style={styles.container}> <Text> {title} </Text> <TextInput onChangeText={this.persistTitle} /> </View> ); } persistTitle = async title => { await AsyncStorage.setItem("title", title); this.setState({ title }); }; } async componentDidMount() { const title = await AsyncStorage.getItem("title"); this.setState({ title }); } render() { const { title } = this.state; return ( <View style={styles.container}> <Text> {title} </Text> <TextInput onChangeText={this.persistTitle} /> </View> ); } persistTitle = async title => { await AsyncStorage.setItem("title", title); this.setState({ title }); };
  6. import { compose, applyMiddleware, createStore } from "redux"; import {

    persistStore, autoRehydrate } from "redux-persist"; const store = createStore( reducer, compose( applyMiddleware(), autoRehydrate() ) ) // in the root of your app persistStore(store, { storage: AsyncStorage });