Get started with redux CDN
MIT licensed
Redux is a predictable state container for JS applications.
Tags:- flux
- redux
- reducer
- react
- reactjs
- hot
- reload
- hmr
- live
- edit
- webpack
Stable version
Copied!
How to start using redux CDN
// Create a Redux store
import { createStore } from 'redux';
// Define the initial state
const initialState = {
counter: 0,
};
// Define the reducer function
function counterReducer(state = initialState, action) {
switch (action.type) {
case 'INCREMENT':
return { ...state, counter: state.counter + 1 };
case 'DECREMENT':
return { ...state, counter: state.counter - 1 };
default:
return state;
}
}
// Create the Redux store using the reducer and initial state
const store = createStore(counterReducer);
// Define the actions
function increment() {
return { type: 'INCREMENT' };
}
function decrement() {
return { type: 'DECREMENT' };
}
// Use the store and actions in your component
function Counter() {
const [state, dispatch] = React.useReducer(store.getReducer(), initialState);
return (
<div>
<button onClick={() => dispatch(increment())}>+</button>
<span>{state.counter}</span>
<button onClick={() => dispatch(decrement())}>-</button>
</div>
);
}
// Render the component and provide the store to the Provider
ReactDOM.render(
<Provider store={store}>
<Counter />
</Provider>,
document.getElementById('root')
);
Copied!
Copied!
All versions
0.12.0
1.0.0
1.0.0-alpha
1.0.0-rc
1.0.1
2.0.0
3.0.0
3.0.1
3.0.2
3.0.3
3.0.4
3.0.5
3.0.6
3.1.0
3.1.1
3.1.2
3.1.3
3.1.4
3.1.5
3.1.6
3.1.7
3.2.0
3.2.1
3.3.0
3.3.1
3.4.0
3.5.0
3.5.1
3.5.2
3.6.0
3.7.0
3.7.1
3.7.2
4.0.0
4.0.0-beta.1
4.0.0-beta.2
4.0.0-rc.1
4.0.1
4.0.2
4.0.3
4.0.4
4.0.5
4.1.0
4.1.0-alpha.0
4.1.1
4.1.2
4.2.0
4.2.0-alpha.0
4.2.1
5.0.0
5.0.0-alpha.0
5.0.0-alpha.1
5.0.0-alpha.2
5.0.0-alpha.3
5.0.0-alpha.4
5.0.0-alpha.5
5.0.0-alpha.6
5.0.0-beta.0
5.0.0-rc.0
5.0.0-rc.1
*** 5.0.1