Get started with redux-logger CDN

MIT licensed

Redux-logger is a library that logs each Redux action and action payload to the console for debugging.

Tags:
  • redux
  • logger
  • redux-logger
  • middleware

Stable version

Copied!

How to start using redux-logger CDN


// Import required libraries
import { createStore, applyMiddleware } from 'redux';
import logger from 'redux-logger/lib/logger';
import thunk from 'redux-thunk';

// Create the initial state
const initialState = { count: 0 };

// Define the reducer function
function counterReducer(state = initialState, action) {
  switch (action.type) {
    case 'INCREMENT':
      return { count: state.count + 1 };
    case 'DECREMENT':
      return { count: state.count - 1 };
    default:
      return state;
  }
}

// Create the Redux store with middleware
const store = createStore(counterReducer, applyMiddleware(logger, thunk));

// Dispatch an action
store.dispatch({ type: 'INCREMENT' });

// Log the dispatched action and its resulting state
console.log('Action:', store.getState().logEntry);
console.log('State:', store.getState());
Copied!
Copied!
Copied!
Copied!

All versions