DEV Community

State

Dillon on February 20, 2023

State - used for values that change over time. useState creates state variables useState takes a single value, which is the base state, initial ...
Collapse
 
dillpap profile image
Dillon

React forms are weird...

funciton ComponentForm () {
const [searchTerm, setSearchTerm] = React.useState('what would you like to search');
return (
<>

Search:

React.useState('what would you like to search');

to fix this have...

{
setSearchTerm(event.target.value)
}}
/>

Collapse
 
dillpap profile image
Dillon

When you are doing searches or forms, a value cannot go from undefined to suddenly defined.

It can go from empty string ('') to having a value, but it can't go from () to having a value.