concept text box in category react

This is an excerpt from Manning's book React Hooks in Action.
Say you have an app that shows products in a long list and has a text box that users type in to filter the list. Your app updates the list as the user types. Each keystroke triggers the code to filter the list anew, requiring React to draw the updated list components to the screen. The expensive filtering process and recalculation and updating of the UI hogs the processing time, reducing the responsiveness of the text box. The experience for the user is one of a lagging, slow text box that doesn’t show their text as they type. Figure 1.16, while obviously not being a perfect representation of how a browser might schedule code to run, does illustrate the point that long-running operations can slow down updates to the screen, causing a poorer experience for users.
In this chapter we start with two examples that explore changing state without updating the UI: first a comparison of managing state with useState and useRef, then a longer example as we manage timers for the
BookablesListcomponent’s new Presentation Mode. The second half of the chapter has two more examples, this time exploring references to DOM elements: automatically setting focus in theBookablesListcomponent and reading the date from a text box for theWeekPickercomponent. The mix of examples will give you a good understanding of how the useRef hook helps you manage state in your components.
But, if someone working at the company wants to book a meeting room for an event in a couple of months, they have to click the Next button again and again until they reach the date they want. It would be better if they could enter a specific date and jump straight to that week. Figure 6.8 shows an improved
WeekPickerUI with a text box and a Go button.Figure 6.8 The WeekPicker component with a text box and a Go button, for direct date entry.
![]()
Listing 6.7 The WeekPicker with a text box and Go button
import React, {useReducer, useRef} from "react"; import reducer from "./weekReducer"; import {getWeek} from "../../utils/date-wrangler"; import { FaChevronLeft, FaCalendarDay, FaChevronRight, FaCalendarCheck } from "react-icons/fa"; export default function WeekPicker ({date}) { const [week, dispatch] = useReducer(reducer, date, getWeek); const textboxRef = useRef(); #A function goToDate () { #B dispatch({ #C type: "SET_DATE", #C payload: textboxRef.current.value #D }); } return ( <div> <p className="date-picker"> // Prev button // Today button <span> <input type="text" ref={textboxRef} #E placeholder="e.g. 2020-09-02" /> <button onClick={goToDate} className="go btn"> #F <FaCalendarCheck/> <span>Go</span> </button> </span> // Next button </p> <p> {week.start.toDateString()} - {week.end.toDateString()} </p> </div> ); }#A Create a ref to hold the reference to the text box