Hey guys,
I can’t seem to resolve an infinite loop issue. I’ve been stuck on this for 3 days. Can someone advice on how to solve this problem please?
I’m working on a daily-log app for my project. Let me explain the project in 3 components.
The structure (from top to bottom)
- The
DailyLog
component has a form that usesQuestion
components into which props are passed. - The
Question
component uses the props to display a question and description. It also contains anInput
component into which props are further passed down. - The
Input
component takes the props and renders the appropriate form input field.
The logic (from bottom to top)
- The
Input
component handles it’s owninputState
. The state is changed when the user inputs something and theonChangeHandler
is triggered. - The
Input
component also has auseEffect()
hook that calls anonInput()
function that was passed down as props fromDailyLog
. - The
onInputHandler()
in theDailyLog
component updates theformState
which is the form-wide state containing all input field values. TheformState
is amended depending on which input field is filled at the time. - The
onInputHandler()
uses theuseCallback()
hook which is supposed to stop an infinite loop caused by any parent/child re-renders. But it doesn’t work
What’s wrong in the code? Please advice.
Thanks a lot!
Suraj