My screen appears an error is "Expected an assignment or function call and instead saw an expression". Anyone can help me fix this case.I try to fix that but it's not working
import { createSlice , createAsyncThunk } from "@reduxjs/toolkit";
export const getPosts = createAsyncThunk ("posts/getPosts" ,
async (dispatch , getState) => {
return await fetch('https://jsonplaceholder.typicode.com/posts')
.then(res => res.json())
}
)
const addPostSlice = createSlice({
name:'add',
initialState:{
posts:[],
status:false
},
reducers: {},
extraReducers: {
[getPosts.pending]:(state ) => {
state.status = "loading"
},
[getPosts.fulfilled]:(state , action) => {
state.status ="success",
state.posts = action.payload
},
[getPosts.rejected]:(state ) => {
state.status = "failed"
},
}
},
)
const { reducer} = addPostSlice
export default reducer