I am pretty new in React and Redux and I am stucked with one problem. My application is a simple ToDo application and I have 2 main pages (they are one component) plain notations and archived notations. This is my problematic code
import React from 'react';
import { Fragment } from 'react/cjs/react.production.min';
import { TableRow } from './TableRow';
import getNotes from '../services/sortNotes';
import { useDispatch, useSelector } from 'react-redux';
import { addNote, filterNotes } from '../redux/actions';
const Table = ({ isArchived, setCurrentNote }) => {
const notes = useSelector(state => {
const { notesReducer } = state;
return notesReducer.notes;
});
return (
<div className="top-table">
<table className="table">
<colgroup>
<col className="first-column" />
<col />
<col />
<col />
<col />
<col className="date-column" />
<col className="last-column" />
</colgroup>
<thead className="table-head">
<tr>
<td></td>
<td>Name</td>
<td>Created</td>
<td>Category</td>
<td>Content</td>
<td>Dates</td>
<td>{
!isArchived ? (
<Fragment>
<button className="table-body-button" id="placehoder">Edit</button>
<button className="table-body-button" id="archive-all">Archive</button>
<button className="table-body-button" id="delete-all">Delete</button>
</Fragment>
) : <button className="table-body-button" id="unarchive-all">Unarchive</button>
}
</td>
</tr>
</thead>
<tbody className="table-body" id="main-content">
{
notes.map(note => (
<TableRow key={note.id} note={note} setCurrentNote={setCurrentNote}>
</TableRow>
))
}
</tbody>
</table>
</div>
)
}
export default Table;
First, I have tried to use filter inside and it was working well, until I pointed, that my apllication have losted it's rerender ability. Next, I have tried to do something inside my reducer, but I don't now how exactly to do this. This is my reducer:
import { ADD_NOTE } from "./types";
const initialState = {
notes: [
{
id: 0,
name: "Shopping List",
created: 'May 20, 2020',
category: 'Task',
content: 'lorem ipsum bla-...',
dates: '',
archive: false
},
{
id: 1,
name: "The theory of evolution",
created: 'July 30, 2020',
category: 'Random_thought',
content: 'The evolution is...',
dates: '',
archive: false
},
{
id: 2,
name: "New Feature",
created: 'December 25, 2020',
category: 'Idea',
content: 'Implemented new feature',
dates: '',
archive: false
},
{
id: 3,
name: "Books",
created: 'February 10, 2021',
category: 'Task',
content: 'New startup',
dates: '',
archive: false
},
{
id: 4,
name: "William Gaddis",
created: 'September 9, 2021',
category: 'Task',
content: 'Meet William',
dates: '',
archive: false
},
{
id: 5,
name: "What about inventions?",
created: 'September 30, 2021',
category: 'Idea',
content: 'Try to develop time machine',
dates: '',
archive: true
}
],
}
export const notesReducer = (state = initialState, action) => {
switch (action.type) {
case ADD_NOTE:
return {
...state,
notes: [...state.notes, action.note]
}
default:
return state;
}
}
So I will be very appreciated if you will help me, because I am really don't know how to solve this. Link to my full code: https://github.com/radush98/task2