No optimization for rerendering when a global state is hooked via nested state
See original GitHub issueI’m trying to build a “form management” library, that allows to structure the form fields in deeply nested objects like this:
{
"field1": {
"id": "field1",
"label": "Label for field1",
"value": "Initial value for field1"
},
"field2": {
"id": "field2",
"label": "Label for field2",
"value": "Initial value for field2"
},
"section": {
"field1": {
"id": "section.field1",
"label": "Label for section.field1",
"value": "Initial value for section.field1"
}
}
}
The form fields themselves are complex objects, too.
Forms are composed by specifying a name attribute on the field components, e.g. <Field name="deeply.nested.sub.field" />. Because state.nested("deeply.nested.sub.field") is not supported, I wrote a function to split that property path and then iteratively call nested on all parts.
When I edit “section.field1” it seems to work, but when I edit “field1” the “section.field1” component also receives an update. You can find the code here: https://codesandbox.io/s/stupefied-joliot-mkkhl?file=/src/App.tsx
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Just Say No to Excessive Re-Rendering in React - GrapeCity
In this article, we will address instances of excessive re-rendering in React applications and demonstrate how to avoid them.
Read more >Preventing rerenders with React.memo and useContext hook.
I can't rely on data from context API by using (useContext hook) to prevent unnecessary rerenders with React.memo.
Read more >5 Ways to Avoid React Component Re-Renderings
These Hooks reduce re-renderings by caching and returning the same result if the inputs are the same without any computations. When the inputs...
Read more >When does React re-render components? - Felix Gerschau
React re-rendering explained and how to optimize React's re-render performance.
Read more >React Hooks - Understanding Component Re-renders - Medium
useState hook is the primary building block which enables functional components to hold state between re-renders. Let's understand the workings ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

verified in your sandbox and in unit tests
your usecase is fully supported with with hookstate 3.0.12 version