This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render() { | |
const { cameraPermission } = this.state; | |
// Render one of 3 things depending on permissions | |
return ( | |
<View style={styles.container}> | |
{cameraPermission === null ? ( | |
<Text>Waiting for permission...</Text> | |
) : cameraPermission === false ? ( | |
<Text>Permission denied</Text> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render() { | |
const { photo } = this.state; | |
return ( | |
<View style={{ flex: 1, width: '100%' }}> | |
{photo ? ( | |
<ImageBackground | |
style={{ flex: 1 }} | |
source={{ uri: photo.uri }} /> | |
) : ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { connect } from 'react-redux'; | |
class Counter extends React.Component { | |
increment = () => { | |
this.props.dispatch({ type: 'INCREMENT' }); | |
} | |
decrement = () => { | |
this.props.dispatch({ type: 'DECREMENT' }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function brokenReducer(state = initialState, action) { | |
switch(action.type) { | |
case 'INCREMENT': | |
// NO! BAD: this is changing state! | |
state.count++; | |
return state; | |
case 'DECREMENT': | |
// NO! BAD: this is changing state too! | |
state.count--; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reducer(state = initialState, action) { | |
switch(action.type) { | |
case 'INCREMENT': | |
return { | |
count: state.count + 1 | |
}; | |
case 'DECREMENT': | |
return { | |
count: state.count - 1 | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
class Counter extends React.Component { | |
increment = () => { | |
// fill in later | |
} | |
decrement = () => { | |
// fill in later | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { render } from 'react-dom'; | |
import Counter from './Counter'; | |
const App = () => ( | |
<div> | |
<Counter /> | |
</div> | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
class Counter extends React.Component { | |
state = { count: 0 } | |
increment = () => { | |
this.setState({ | |
count: this.state.count + 1 | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { | |
BrowserRouter as Router, | |
Route, | |
Link | |
} from 'react-router-dom'; | |
import './App.css'; | |
class UsersView extends Component { | |
state = {users: []} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import './App.css'; | |
class App extends Component { | |
state = {users: []} | |
componentDidMount() { | |
fetch('/users') | |
.then(res => res.json()) | |
.then(users => this.setState({ users })); |