"
Before you use the React Redux bindings, learn how to create a complete simple application with just React and Redux.
[/span>html
[/span>head
[/span>meta charset=""utf-8""
//代码效果参考:https://v.youku.com/v_show/id_XNjQwNjg2OTc3Ng==.html
[/span>title[/span>script src=""""
[/span>script src=""""
[/span>script src=""""
[/span>body
[/span>div id='root'
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
//代码效果参考:https://v.youku.com/v_show/id_XNjQwNjg2OTg0OA==.html
return state + 1;case 'DECREMENT':
return state - 1;
default:
return state;
}
}
const Counter = ({
value,
onIncrement,
onDecrement
}) => (
{value}
+
-
);
const { createStore } = Redux;
const store = createStore(counter);
const render = () => {
ReactDOM.render(
[span style=""color: rgba(0, 0, 0, 1)"">Counter
value={store.getState()}
onIncrement={() =>
store.dispatch({
type: 'INCREMENT'
})
}
onDecrement={() =>
store.dispatch({
type: 'DECREMENT'
})
}
/>,
document.getElementById('root')
);
};
store.subscribe(render);
render();
From React 0.14, you can declear a compoment by using a function.
"