Counter react / redux example
According to egghead video tutorial.
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.2.1/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.2.1/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.5.2/redux.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.30.0/react-bootstrap.js"></script>
<script src="https://babeljs.io/scripts/babel.js"></script>
<div id="root">
</div>
<script id="jsx-babelify" type="text/babel-jsx">
const counter = (state = 0, action) => {
switch(action.type) {
case 'ACTION':
return state + 1;
default:
return state;
}
}
class Counter extends React.Component {
constructor(props) {
super(props)
this.state = {}
}
componentWillMount() {
this.props.some()
this.props.some()
this.props.some()
this.props.some()
this.props.some()
this.props.some()
this.setState({
textValue: this.props.value
})
}
componentWillReceiveProps(nextProps) {
console.log('props', nextProps)
this.setState({
textValue: this.props.value
})
}
render() {
console.log('render with: ',this.state.textValue)
return (
<div>
<b>1.</b> Bootstrap defaultValue: <br/>
<ReactBootstrap.FormControl
name="text"
placeholder="Enter Text"
maxLength="250"
defaultValue={this.state.textValue}
required
/> <hr />
<b>2.</b> Input defaultValue: <br/>
<input type="text" defaultValue={this.state.textValue} /> <hr />
<b>3.</b> Input value: <br/>
<input type="text" value={this.state.textValue} />
</div>
);
}
}
const {createStore} = Redux;
const store = createStore(counter); // bind reducer
const render = () => {
ReactDOM.render(
<Counter
value={store.getState()}
some={() => {
setTimeout(() => store.dispatch({type: 'ACTION'}), 100)
}} />,
...