Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created November 2, 2017 13:12
Show Gist options
  • Save mizchi/f674e4fb58837fe62eadc75b688974f5 to your computer and use it in GitHub Desktop.
Save mizchi/f674e4fb58837fe62eadc75b688974f5 to your computer and use it in GitHub Desktop.
Isolate
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<main></main>
<script crossorigin src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/redux@3.7.2/dist/redux.min.js"></script>
<script crossorigin src="https://unpkg.com/react-redux@5.0.6/dist/react-redux.min.js"></script>
<script type="text/babel" data-presets="react" >"use strict;";
// reducer
const counter = (state = { value: 0 }, action = { type: 'nop' }) => {
switch (action.type) {
case 'increment':
return { value: state.value + 1 }
default:
return state
}
}
const store = Redux.createStore(counter)
// component
const { connect, Provider } = ReactRedux
const App = connect(s => s)(props => {
const { value, dispatch } = props
return (
<div>
<h1>Counter</h1>
<span>
{value}
</span>
<button onClick={() => dispatch({ type: 'increment' })}>+1</button>
</div>
)
})
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.querySelector('main')
)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment