Test your knowledge and skills with this sprint challenge. You'll build a real-world application that demonstrates your understanding of state management in React applications.
In this sprint challenge, you will create a Redux-powered application that demonstrates your mastery of advanced state management techniques. You'll implement a robust architecture using Redux Toolkit, create efficient data flows with Redux slices, and manage API interactions with Redux Thunk and RTK Query.
npm install
to install dependenciesnpm start
to start the development server// Example Redux store setup
import { configureStore } from '@reduxjs/toolkit';
import postsReducer from './features/posts/postsSlice';
import commentsReducer from './features/comments/commentsSlice';
import { apiSlice } from './api/apiSlice';
export const store = configureStore({
reducer: {
posts: postsReducer,
comments: commentsReducer,
[apiSlice.reducerPath]: apiSlice.reducer,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(apiSlice.middleware),
});
// Example thunk action
export const fetchPosts = createAsyncThunk(
'posts/fetchPosts',
async (_, { rejectWithValue }) => {
try {
const response = await axios.get('/api/posts');
return response.data;
} catch (error) {
return rejectWithValue(error.response.data);
}
}
);
// Example RTK Query setup
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
export const apiSlice = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({ baseUrl: '/api' }),
tagTypes: ['Post', 'Comment'],
endpoints: (builder) => ({
getPosts: builder.query({
query: () => '/posts',
providesTags: ['Post']
}),
addPost: builder.mutation({
query: (post) => ({
url: '/posts',
method: 'POST',
body: post
}),
invalidatesTags: ['Post']
})
})
});
Make sure to:
Submission deadline: Check your course calendar for the specific due date and time.