The text area and button elements are highlighted in bold for convenience. We have a function addCommentHandler () that is called on clicking the button. When the button is clicked, we need to get the content of the text-area and make a API POST request. To get the content of the text-area we use use React useRef hook. To get the value of an uncontrolled input on button click in React: 1. How to convert PHP file to PDF file or create pdf file from webpage Using mpdf Tips & tricks for text detection from images using Google Vision API in PHP How to install or upgrade php 7.3 All modern browsers come with an inbuilt Fetching Data in
import React, { useState} from 'react'; The useState function is a Hook that How do make an api fetch request on button click Reactjs? It doesnt matter what backend technology you are using (i.e Nodejs, WordPress, etc) you can React hooks are async so when you are running console.log(students) right after running setStudents(data) it is still not populated, however th It would be nice to have the API call in a function that we can call, not only in useEffect, but also from the click of a button. Initialize a ref using the useRef hook and set it on the input field. Introducing useState The useState hook is the first one to learn about and to use it we import it into a file like so. In a regular app, you'd use