javascript - React: TextField onchange - Stack Overflow

I have a list of data that lists on the collapse, I just want to display in my collapse what i put on m

I have a list of data that lists on the collapse, I just want to display in my collapse what i put on my Textfield

const onChangeLocation = (locations) =>{
    console.log(locations)
  }

   <TextField
      size="small"
      fullWidth
      onChange={onChangeLocation}
      variant="standard"
      placeholder="Search Locations"
      onFocus={openSearch}
      value={searchParameter}
      }}
    />

  <Collapse in={viewLocationList} sx={{ my: '2px' }}>
    <Box className="rounded-scrollbar widget-result-container">
      {locations.map((location, index) => (
        <LocationWidgetItem
          key={index}
          location={location}
          onClickLocation={setActiveLocation}
        />
      ))}
    </Box>
  </Collapse>

I have a list of data that lists on the collapse, I just want to display in my collapse what i put on my Textfield

const onChangeLocation = (locations) =>{
    console.log(locations)
  }

   <TextField
      size="small"
      fullWidth
      onChange={onChangeLocation}
      variant="standard"
      placeholder="Search Locations"
      onFocus={openSearch}
      value={searchParameter}
      }}
    />

  <Collapse in={viewLocationList} sx={{ my: '2px' }}>
    <Box className="rounded-scrollbar widget-result-container">
      {locations.map((location, index) => (
        <LocationWidgetItem
          key={index}
          location={location}
          onClickLocation={setActiveLocation}
        />
      ))}
    </Box>
  </Collapse>
Share Improve this question asked Dec 27, 2021 at 6:48 RogerRoger 3931 gold badge4 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Are you using the state to store the location you are getting from textfield? If not please use the state to store the input you get from textfield into a state like this -

const [location, setLocation] = useState('')

const onChangeLocation = (event) => {
 setLocation(event.target.value)
}

<TextField
  size="small"
  fullWidth
  onChange={onChangeLocation}
  variant="standard"
  placeholder="Search Locations"
  onFocus={openSearch}
  value={location}
  }}
 />

  <Collapse in={viewLocationList} sx={{ my: '2px' }}>
    <Box className="rounded-scrollbar widget-result-container">
      {locations.map((location, index) => (
        <LocationWidgetItem
          key={index}
          location={location}
          onClickLocation={setActiveLocation}
        />
      ))}
    </Box>
  </Collapse>

If you are using the state to store the location then too you can use the code above. Your code was not working because you are not sending the param from your textfield and the function onChangeLocation is expecting an argument which it isn't getting so it should be returning undefined.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745224290a4617389.html

相关推荐

  • javascript - React: TextField onchange - Stack Overflow

    I have a list of data that lists on the collapse, I just want to display in my collapse what i put on m

    13小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信