and
Title text field
let title = "";
Event
Watcher
const SpecTile = props => {
let originalBackgroundTitle = 'rgba(0, 0, 0, 0.4)';
let { keyProp, selectedKey, handleGridTileClick, image, images } = props;
return (
<GridTile
style={styles.hoverCursorPointer}
titleBackground={
selectedKey === keyProp ? blue500 : originalBackgroundTitle
}
title={image.gameName}
onClick={e => {
handleGridTileClick(keyProp, image);
}}
>
<img
src={images[image.gameIcon512x512].downloadURL}
alt={images[image.gameIcon512x512].id}
/>
</GridTile>
);
};
Better separation of concerns
const SearchBar = (props) => {
return <input type="search"
onChange={(e, newValue) => {props.handleSearch(e, newValue)}}/>
}
class App extends React.Component {
state = {
searchText: ''
};
handleSearch(e, newValue) {
this.setState({...this.state, searchText: newValue});
}
render() {
return (<SearchBar handleSearch={this.handleSearch.bind(this)} />);
}
}
Predictable State Container for JavaScript Apps
As applications become complex, managing state becomes pain
Libraries like react remove asynchronicity and direct DOM manipulation but you still need to maintain state
State bloats with every increasing demands of a UI platform
The state of your whole application is stored in an object tree within a single store.
The only way to change the state is to emit an action, an object describing what happened.
To specify how the state tree is transformed by actions, you write pure reducers.
These reducers take in old state and an action and return back new state
(previousState, action) => newState