Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Up Redux ToolKit #33

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.cjs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you changed this file?

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
'react/react-in-jsx-scope': 0,
'import/no-extraneous-dependencies': 0,
'import/extensions': 0,
'no-param-reassign': 0,
},
ignorePatterns: ['dist/**/*', 'postcss.config.js', 'tailwind.config.js'],
};
23 changes: 23 additions & 0 deletions src/Redux/EcommerceReducer.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the use of this file in configuring redux?

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createSlice } from '@reduxjs/toolkit';

interface IsLoggedIn {
value: boolean;
}

const initialState: IsLoggedIn = {
value: false,
};

const ecommerceSlice = createSlice({
name: 'IsLoggedIn',
initialState,
reducers: {
login: (state) => {
state.value = true;
},
},
});

export const { login } = ecommerceSlice.actions;

export default ecommerceSlice.reducer;
5 changes: 5 additions & 0 deletions src/Redux/Hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { useDispatch, useSelector, TypedUseSelectorHook } from 'react-redux';
import type { RootState, AppDispatch } from './store';

export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
8 changes: 8 additions & 0 deletions src/Redux/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { combineReducers } from '@reduxjs/toolkit';
import ecommerceReducer from './EcommerceReducer';

const rootReducer = combineReducers({
ecommerce: ecommerceReducer,
});

export default rootReducer;
11 changes: 11 additions & 0 deletions src/Redux/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { configureStore } from '@reduxjs/toolkit';
import rootReducer from './index';

const store = configureStore({
reducer: rootReducer,
});

export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

export default store;
6 changes: 6 additions & 0 deletions src/index.css
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have you changed this file while setting up redux?

Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
@import url('https://fonts.googleapis.com/css2?family=Lexend:wght@100..900&display=swap');

@tailwind base;
@tailwind components;
@tailwind utilities;

* {
font-family: 'Lexend', sans-serif;
}
10 changes: 7 additions & 3 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { Provider } from 'react-redux';
import store from './Redux/store';
import App from '@/App.tsx';
import '@/index.css';

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
<Provider store={store}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exchange lines 10 and 9.
ie: Line 10 should come first on line 9 and line 9 should be on line 10.
example:
<React.StrictMode> <Provider store={store}> <App /> </Provider> </React.StrictMode>

<React.StrictMode>
<App />
</React.StrictMode>
</Provider>
);
Loading