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
DailyLogcomponent has a form that usesQuestioncomponents into which props are passed. - The
Questioncomponent uses the props to display a question and description. It also contains anInputcomponent into which props are further passed down. - The
Inputcomponent takes the props and renders the appropriate form input field.
The logic (from bottom to top)
- The
Inputcomponent handles it’s owninputState. The state is changed when the user inputs something and theonChangeHandleris triggered. - The
Inputcomponent also has auseEffect()hook that calls anonInput()function that was passed down as props fromDailyLog. - The
onInputHandler()in theDailyLogcomponent updates theformStatewhich is the form-wide state containing all input field values. TheformStateis 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
