According to React Final Form documentation, I can pass onChange callback to <FormSpy /> component to execute code when form state changes. However, I also discovered that if I need to run some function every time when the form changes, I can also put this function inside Form's render callback before return statement:
<Form
onSubmit={onSubmit}
render={({ handleSubmit }) => {
myFunctionToRunOnChange(); // Call function here
return (
<form onSubmit={handleSubmit}>
<div>
<label>First Name</label>
<Field name="firstName" component="input" placeholder="First Name" />
</div>
<button type="submit">Submit</button>
</form>
);
}}
/>
Is it good practice? For example, comparing with using FormSpy for onChange...