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?