26 lines
541 B
JavaScript
26 lines
541 B
JavaScript
import { createSlice } from '@reduxjs/toolkit'
|
|
import moment from 'moment';
|
|
|
|
export const postsSlice = createSlice({
|
|
name: 'counter',
|
|
initialState: {
|
|
posts: []
|
|
},
|
|
reducers: {
|
|
addPost: (state,{payload}) => {
|
|
let uuid = window.crypto.randomUUID();
|
|
state.posts.unshift({
|
|
id: uuid,
|
|
date: moment().toJSON(),
|
|
context: payload
|
|
})
|
|
}
|
|
}
|
|
})
|
|
|
|
// Action creators are generated for each case reducer function
|
|
export const {
|
|
addPost
|
|
} = postsSlice.actions
|
|
|
|
export default postsSlice.reducer |