I'm trying to implement a file upload button. I want to store the user's selected files in a redux store using redux-toolkit. My code works but I get the warning "A non-serializable value was detected in the state". How can I improve my code to get rid of the warning?
//Code to create slice
const initialState = {
listOfSelectedFiles: [0]
};
export const modalSlice = createSlice({
name: 'modal',
initialState,
reducers:
{
addFileToList: (state, action) =>
{ //Add selected file to state
state.listOfSelectedFiles.push(action.payload)
}
}
});
//Function inside react component to handle uploads
const HandleSelectedFiles = event => {
const uploadedFiles = event.target.files[0];
dispatch(addFileToList(uploadedFiles))
};