I have 2 components (to simplifiy the web app we running, since it’s much larger in complexicty)
of page.tsx and a component of counter.tsx.
sometime i need to update the counter, which has a state inside the counter component. however I couldn’t “make it work” without triggering rendering often in the parent page. If i place the state in the parent (i end up triggering the parent, page.tsx often because it’s a timer and it ticks every 1000ms) and having the state inside the counter.tsx means i can’t trigger the setState from parent (or can i? if so, how?)
- mind you i don’t want to trigger re-render of the parent component
- If i “uplift” the state (as react docs suggest) i end up triggering the child and parent component which is a lot of re-rendering!
- state inside child component (setState not accesible to parent)
- state inside parent component (and child become “stateless”) – but parent ends up rendering every 1000ms
- “updater” func in parent that receives a CB that trigger the setState inside the child (didn’t work) but sometime the cb works sometime it doesn’t
- i tried useMemo, but couldn’t use it very much.
any ideas?
oliviarizona is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4