concept user interaction in category isomorphic web applications

This is an excerpt from Manning's book Isomorphic Web Applications: Universal Development with React.
Historically, web apps and websites have come in two forms: server-rendered and single-page apps (SPAs). Server-rendered apps handle each action the user takes by making a new request to the server. In contrast SPAs handle loading the content and responding to user interactions entirely in the browser. Isomorphic web apps are a combination of these two approaches.
By the end of this section, you’ll be able to build a user interface for a Todo application (see figure 3.1) with user interactions. You’ll have used all the React features necessary for building isomorphic applications. To follow along with the examples in this chapter, check out the react-components branch in the GitHub repository (git checkout react-components).
Listing 4.11. Clearing the timer on user interaction—src/components/products.jsx
class Products extends React.Component { componentDidMount() { this.clearTimer = setTimeout(() => { #1 this.setState({ showToolTip: true }); }, 10000); } componentWillUpdate(nextProps, nextState) { #2 if (nextState.searchQuery.length > 0) { clearTimeout(this.clearTimer); #3 } console.log('cWU'); #4 } updateSearchQuery() {} } #1 Capture return value of setTimeout so timer can be cleared. #2 When component receives new state, check state for presence of search query. #3 Clear timer. #4 Log shows that the componentWillUpdate method fires each time a letter is typed into the search box (with abbreviation cWU). !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":2,\"ch\":3},{\"line\":2,\"ch\":56}],[{\"line\":9,\"ch\":1},{\"line\":9,\"ch\":56}],[{\"line\":10,\"ch\":3},{\"line\":10,\"ch\":42}],[{\"line\":11,\"ch\":5},{\"line\":11,\"ch\":56}],[{\"line\":5,\"ch\":5},{\"line\":5,\"ch\":6}],[{\"line\":6,\"ch\":3},{\"line\":6,\"ch\":4}],[{\"line\":7,\"ch\":1},{\"line\":7,\"ch\":2}],[{\"line\":12,\"ch\":3},{\"line\":12,\"ch\":4}],[{\"line\":14,\"ch\":1},{\"line\":14,\"ch\":2}],[{\"line\":15,\"ch\":22},{\"line\":15,\"ch\":23}],[{\"line\":16,\"ch\":0},{\"line\":16,\"ch\":1}],[{\"line\":13,\"ch\":3},{\"line\":13,\"ch\":56}],[{\"line\":5,\"ch\":5},{\"line\":5,\"ch\":6}],[{\"line\":6,\"ch\":3},{\"line\":6,\"ch\":4}],[{\"line\":7,\"ch\":1},{\"line\":7,\"ch\":2}],[{\"line\":12,\"ch\":3},{\"line\":12,\"ch\":4}],[{\"line\":14,\"ch\":1},{\"line\":14,\"ch\":2}],[{\"line\":15,\"ch\":22},{\"line\":15,\"ch\":23}],[{\"line\":16,\"ch\":0},{\"line\":16,\"ch\":1}]]"} !@%STYLE%@!