Question:
How to update the react component after clicking on the search button?

To update the react component after clicking on the search button the e.target should be called with the argument being the name or id of the form element you want to target, not the string "query". 


Additionally, you should use e.target.value to get the value of the input field. Here's the code:


import { useState } from "react";

import CountrySWR from "./CountrySWR";



export default function SearchForm(){

    const [countryName, setCountryName] = useState("a");


 const handleSubmit = (e:any) => {

    e.preventDefault();

    // in here query is a id of input which located in form

      console.log(e.target.query.value)

}


    return (

        <>

<form onSubmit={handleSubmit}>

  <input id='query' type="text" />

  <button type='submit'>submit</button>

</form>

            <CountrySWR name={countryName}/>

        </>

    );

};



Answered by: >Andy Johnston

Credit:> Stack Overflow


Suggested blogs:

>How to test the post-Django function?

>How to filter events by month in Django?

>Implement nested serializers in the Django rest framework

>Solved: TaskList View in Django

>Sending Audio file from Django to Vue

>Creating a form in Django to upload a picture from website

>Fix webapp stops working issue in Django- Python webapp

>How to manage the Text in the container in Django?


Submit
0 Answers

What Our Clients Say About Us

Client satisfaction is our ultimate goal. Here are some kind words of our precious clients they have used to express their satisfaction with our service.

Why Choose Us ?

We endow businesses with flexible engagement models based on their unique needs. Our strength lies in state-of-the-art technology and affordable consulting services. Try us for fast POCs, full-fledged applications, or technology consulting. Always available for your service.