Beginner's Thread / Easy Questions (June 2022)

Practicing with React as an Angular dev, still trying to wrap my head around hooks.

So, I got this Add/Edit form. If a `food` prop is passed, it uses that data to populate the form, and if not, it'll reset the form to the default values. Currently that portion of the code looks like this:

useEffect (() => {
props.food ? form.setValues(props.food) : form.reset();
}, []);

This then complains about `form` and `props.food` not being in the deps array. The thing is, having the form there would cause the component to re-render forever.

Essentially, I want this but to run only once when the component is initiated. Is there a better way of achieving this?

/r/reactjs Thread