[리액트] react-final-form

JJeong·2021년 3월 30일
0

배경

리액트에서는 <form>를 잘 사용하지 않는다. form 요소의 값을 state로 관리하는 경우가 많기에 굳이 해당 태그를 사용하지 않아도 onClick 이벤트만으로 값을 따오고 가공하여 api를 호출하는 일이 가능하기 때문이다. 그럼에도 사용자 폼은 변수가 많아 작성하기 까다로운 부분이 있다. 이 때 라이브러리를 사용하면 state로 관리하지 않고 기타 부가 기능까지 쉽게 추가할 수 있다.


  1. Provide an onSubmit prop
    onSubmit is a function that will be called with the values of your form when the user submits the form and all validation passes. Your onSubmit function will not be called if there are validation errors.
  1. Provide a way to render the form
  1. Do something with handleSubmit
    The most important thing that will pass to your render function is the handleSubmit function. handleSubmit is a convenience method designed to be passed as the onSubmit prop to an HTML component. handleSubmit will call event.preventDefault() to stop the default browser submission process.

0개의 댓글