React & Modern Frontend (445 Qs)•Part 8: Advanced React Patterns, Portals & Performance (152 - 261)
Can Redux only be used with React?
Redux can be used as a data store for any UI layer. The most common usage is with React and React Native, but there are bindings available for Angular, Angular 2, Vue, Mithril, and more. Redux simply provides a subscription mechanism which can be used by any other code.
Practical Code Example
javascript
// Redux can be used with ANY UI framework or vanilla JavaScript:
import { createStore } from 'redux';
function counter(state = 0, action) {
return action.type === 'INC' ? state + 1 : state;
}
const store = createStore(counter);
store.subscribe(() => console.log('State:', store.getState()));
store.dispatch({ type: 'INC' }); // Logs: State: 1