This file contains 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 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 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 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 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 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 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 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 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 })); |
This file contains 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
"scripts": { | |
"start": "react-scripts start", | |
"build": "react-scripts build", | |
"test": "react-scripts test --env=jsdom", | |
"eject": "react-scripts eject" | |
}, | |
"proxy": "http://localhost:3001" |