File tree Expand file tree Collapse file tree 5 files changed +11
-48
lines changed Expand file tree Collapse file tree 5 files changed +11
-48
lines changed Original file line number Diff line number Diff line change 1001
1001
"createdAt" : 1657255275073 ,
1002
1002
"id" : 143
1003
1003
},
1004
- {
1005
- "title" : " tt" ,
1006
- "body" : " tt" ,
1007
- "publish" : false ,
1008
- "createdAt" : 1657774109980 ,
1009
- "id" : 144
1010
- },
1011
- {
1012
- "title" : " af" ,
1013
- "body" : " fg" ,
1014
- "publish" : false ,
1015
- "createdAt" : 1657774124639 ,
1016
- "id" : 145
1017
- },
1018
- {
1019
- "title" : " a" ,
1020
- "body" : " a" ,
1021
- "publish" : false ,
1022
- "createdAt" : 1657774343111 ,
1023
- "id" : 146
1024
- },
1025
- {
1026
- "title" : " a" ,
1027
- "body" : " a" ,
1028
- "publish" : false ,
1029
- "createdAt" : 1657774405686 ,
1030
- "id" : 147
1031
- },
1032
- {
1033
- "title" : " b" ,
1034
- "body" : " b" ,
1035
- "publish" : false ,
1036
- "createdAt" : 1657774415721 ,
1037
- "id" : 148
1038
- },
1039
1004
{
1040
1005
"title" : " b" ,
1041
1006
"body" : " b" ,
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ import { useLocation } from 'react-router-dom';
8
8
import propTypes from 'prop-types' ;
9
9
import Toast from '../components/Toast' ;
10
10
import useToast from '../hooks/toast' ;
11
- import { useSelector } from 'react-redux' ;
12
11
13
12
const BlogList = ( { isAdmin } ) => {
14
13
const history = useHistory ( ) ;
@@ -21,10 +20,6 @@ const BlogList = ({ isAdmin }) => {
21
20
const [ numberOfPosts , setNumberOfPosts ] = useState ( 0 ) ;
22
21
const [ numberOfPages , setNumberOfPages ] = useState ( 0 ) ;
23
22
const [ searchText , setSearchText ] = useState ( '' ) ;
24
- const toasts1 = useSelector ( ( state ) => {
25
- return state . toast . toasts ;
26
- } ) ;
27
- console . log ( 'hello' , toasts1 )
28
23
29
24
const [ toasts , addToast , deleteToast ] = useToast ( ) ;
30
25
const limit = 5 ;
Original file line number Diff line number Diff line change 1
1
import PropTypes from 'prop-types' ;
2
- import { useSelector } from 'react-redux' ;
3
2
4
3
const Card = ( { title, onClick, children } ) => {
5
- const toasts = useSelector ( ( state ) => {
6
- return state . toast . toasts ;
7
- } ) ;
8
- console . log ( 'hello1' , toasts ) ;
9
4
return (
10
5
< div
11
6
className = "card mb-3 cursor-pointer"
Original file line number Diff line number Diff line change 1
1
import { useState , useRef } from 'react' ;
2
2
import { v4 as uuidv4 } from 'uuid' ;
3
+ import { addToast as add } from '../store/toastSlice' ;
4
+ import { useDispatch } from 'react-redux' ;
3
5
4
6
const useToast = ( ) => {
5
7
const [ , setToastRerender ] = useState ( false ) ;
6
8
const toasts = useRef ( [ ] ) ;
9
+ const dispatch = useDispatch ( ) ;
7
10
8
11
const deleteToast = ( id ) => {
9
12
const filteredToasts = toasts . current . filter ( toast => {
@@ -21,8 +24,9 @@ const useToast = () => {
21
24
id
22
25
}
23
26
24
- toasts . current = [ ...toasts . current , toastWithId ] ;
25
- setToastRerender ( prev => ! prev ) ;
27
+ dispatch ( add ( toastWithId ) ) ;
28
+ // toasts.current = [...toasts.current, toastWithId];
29
+ // setToastRerender(prev => !prev);
26
30
27
31
setTimeout ( ( ) => {
28
32
deleteToast ( id , toasts , setToastRerender ) ;
Original file line number Diff line number Diff line change @@ -8,8 +8,12 @@ const toastSlice = createSlice({
8
8
name : 'toast' ,
9
9
initialState,
10
10
reducers : {
11
-
11
+ addToast : ( state , action ) => {
12
+ state . toasts . push ( action . payload ) ;
13
+ }
12
14
}
13
15
} )
14
16
17
+ export const { addToast } = toastSlice . actions ;
18
+
15
19
export default toastSlice . reducer ;
You can’t perform that action at this time.
0 commit comments