A React application that showcases a photo gallery powered by Redux Toolkit. It features asynchronous data fetching, middleware logging, and integration with Redux DevTools for efficient state management and debugging.
- Asynchronous data fetching using
createAsyncThunk - State management with Redux Toolkit's
createSlice - Middleware integration with
redux-loggerfor action and state change logging - Redux DevTools support for enhanced debugging
- Responsive UI displaying photos in a grid layout
-
Clone the repository:
git clone git@github.com:prashankulathunga/REDUX-PHOTO-GALLERY.git cd REDUX-PHOTO-GALLERY -
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
Open your browser and navigate to
http://localhost:3000to view the application.
├── public/
├── src/
│ ├── components/
│ ├── redux/
│ │ ├── Store.jsx
│ │ └── feature/
│ │ ├── gallery/
│ │ │ └── GallerySlice.jsx
│ │ └── theme/
│ │ └── ThemeSlice.jsx
│ ├── App.jsx
│ ├── App.css
│ ├── index.css
│ └── main.jsx
├── .gitignore
├── index.html
├── vite.config.js
├── eslint.config.js
├── package.json
├── package-lock.json
└── README.md"""
- React: Front-end library for building user interfaces.
- Redux Toolkit: Simplifies Redux state management with less boilerplate.
- createAsyncThunk: Handles asynchronous operations like API calls.
- redux-logger: Middleware for logging dispatched actions and state changes.
- Redux DevTools: Browser extension for inspecting Redux state and actions.
The application fetches photos from the Picsum Photos API.
Example API call using createAsyncThunk:
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import axios from "axios";
export const fetchImages = createAsyncThunk('gallery/fetchImages', async(page = 1)=>{
const result = await axios.get(`https://picsum.photos/v2/list?limit=12&page=${page}`);
return result.data
})The Redux store is configured with redux-logger middleware and Redux DevTools extension:
import { configureStore } from "@reduxjs/toolkit";
import logger from "redux-logger";
import { themeReducer } from "./feature/theme/ThemeSlice";
import { galleryReducer } from "./feature/gallery/GallerySlice";
const store = configureStore({
reducer:{
theme: themeReducer,
gallery: galleryReducer
},
middleware: (getDefaultMiddleware)=>{
return [...getDefaultMiddleware(), logger]
}
})
export default store;Contributions are welcome! Please fork the repository and submit a pull request for any enhancements or bug fixes.
This project is licensed under the MIT License.