Skip to content

Commit ef6c154

Browse files
committed
71
1 parent b09e8fa commit ef6c154

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

src/components/BlogList.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useLocation } from 'react-router-dom';
88
import propTypes from 'prop-types';
99
import Toast from '../components/Toast';
1010
import useToast from '../hooks/toast';
11+
import { useSelector } from 'react-redux';
1112

1213
const BlogList = ({ isAdmin }) => {
1314
const history = useHistory();
@@ -20,6 +21,10 @@ const BlogList = ({ isAdmin }) => {
2021
const [numberOfPosts, setNumberOfPosts] = useState(0);
2122
const [numberOfPages, setNumberOfPages] = useState(0);
2223
const [searchText, setSearchText] = useState('');
24+
const toasts1 = useSelector((state) => {
25+
return state.toast.toasts;
26+
});
27+
console.log('hello', toasts1)
2328

2429
const [toasts, addToast, deleteToast] = useToast();
2530
const limit = 5;

src/components/Card.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import PropTypes from 'prop-types';
2+
import { useSelector } from 'react-redux';
23

34
const Card = ({ title, onClick, children }) => {
5+
const toasts = useSelector((state) => {
6+
return state.toast.toasts;
7+
});
8+
console.log('hello1', toasts);
49
return (
510
<div
611
className="card mb-3 cursor-pointer"

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
33
import './index.css';
44
import App from './App.js';
55
import { Provider } from 'react-redux';
6-
import { store } from './store';
6+
import { store } from './store/store';
77

88
ReactDOM.render(
99
<Provider store={store}>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { configureStore } from '@reduxjs/toolkit'
2+
import toastReducer from './toastSlice'
23

34
export const store = configureStore({
4-
reducer: {},
5+
reducer: {
6+
toast: toastReducer
7+
},
58
})

src/store/toastSlice.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { createSlice } from '@reduxjs/toolkit';
2+
3+
const initialState = {
4+
toasts: []
5+
};
6+
7+
const toastSlice = createSlice({
8+
name: 'toast',
9+
initialState,
10+
reducers: {
11+
12+
}
13+
})
14+
15+
export default toastSlice.reducer;

0 commit comments

Comments
 (0)