I am making a simple note taking app in React. Here's what it looks like so far:
Each note bullet is a 'Cell' component which contains an inner div for more child Cell components. The App contains a div for the navbar and a div for notes, and in the notes div I render the Cells using .map(). Notes are stored in the App state like this...
notes: [
{
contents: "Learn React",
children: [
{
contents: "Finish tutorial series",
children: []
},
{
contents: "Do example project",
children: []
}
]
},
{
contents: "Learn Redux",
children: []
},
{
contents: "Build note-taking app",
children: []
}
]
(I have a function in the constructor that dynamically gives an id number to each note before rendering the App.)
My issue is that every time the user modifies a note, that modifies the corresponding note in the notes object in the App state (Cells have an onBlur handler passed from App that passes up the Cell's id and I then search the notes object of that id and change the content), and this causes the entire page to rerender since the top level state changed. Doesn't this defeat the whole purpose of React? If the whole App component gets re-rendered when its state changes I'd think 'lifting up state' to the App level would be bad, but it seems like React encourages this.
I need to store the notes at the top level state so I can export them or change to a new page of notes using the navbar, but if I do this then every time I change any bullet note, every other one also re-renders, isn't that a problem?