Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
<script src="https://fb.me/react-15.1.0.js"></script>
<script src="https://fb.me/react-dom-15.1.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.7.2/redux.min.js"></script>
</head>
<body>
 <div id="root"></div>
</body>
</html>
 
const initialState = {
  count: 0
};
const reducer = (state = initialState, action) => {
  
  switch (action.type) {
    case 'INCREMENT':
      return { 
        ...state, 
        count: state.count + 1 
      }
    case 'DECREMENT':
      return { 
        ...state, 
        count: state.count - 1 
       }
    case 'RESET':
      return { 
        ...state, 
        count: state.count = 0
    }
    default:
      return state
  }
}
const store = Redux.createStore(reducer);
const Counter = (props) => {
  const { value, onIncrement, onDecrement, onReset } = props;
  return (
    <div>
        <h1>{value}</h1>
        <button onClick={onIncrement}>+</button>
        <button onClick={onReset}>Reset</button>
        <button onClick={onDecrement}>-</button>
    </div>
  );
}
const render = () => {
  ReactDOM.render(
    <Counter 
      value={store.getState().count}
      onIncrement={() => store.dispatch({ type : 'INCREMENT' })}
      onDecrement={() => store.dispatch({ type : 'DECREMENT' })}
      onReset={() => store.dispatch({ type : 'RESET' })}
    />,
    document.getElementById('root')
  );
};
store.subscribe(() => {
  console.log(store.getState());
  render();
})
render()
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers