formik focus on first error code example
Example: formik error focus
export default class ScrollToError extends React.Component {
componentDidUpdate(prevProps) {
if (prevProps.submitCount !== this.props.submitCount && !this.props.isValid) {
if (Object.keys(this.props.errors)[0] === this.props.name) {
ReactDOM.findDOMNode(this.props.inputRef.current).scrollIntoView({ behavior: 'smooth' });
}
}
}
render() {
return null;
}
}