Giter Club home page Giter Club logo

Comments (4)

tyleri avatar tyleri commented on June 26, 2024

Can you copy and paste your code for onSearchSubmit? It seems to work fine for me, and I've been following the version of the PDF I downloaded on December 18th.

from the-road-to-learn-react.

rwieruch avatar rwieruch commented on June 26, 2024

As a reference https://github.com/rwieruch/hackernews-client that might help.

from the-road-to-learn-react.

rwieruch avatar rwieruch commented on June 26, 2024

Will close this now, because we didn't hear anything back.

from the-road-to-learn-react.

cwoz117 avatar cwoz117 commented on June 26, 2024

I see this error on:

  • Firefox Developer Edition 67.0b16 (64-bit)
  • Microsoft Edge 44.17763.1.0
  • Chrome Version 74.0.3729.131 (Official Build) (64-bit)

with versions running on Ubuntu18.04 WSL:

  • nodejs version v8.10.0
  • npm version 3.5.2
  • react version 16.8.5-canary-297165f1e

The physical book I'm using has its last changelog as 10. January 2017, but this section in chapter 3 appears unchanged (hard to diff w/ a piece of paper)

The code previously requested is below, and I have tried it without the anon function as well.

onSearchSubmit = (event) => {
  const {searchTerm} = this.state
  this.fetchSearchTopStories(searchTerm);
  event.preventDefault();
}

[EDIT]: The issue arose when the guide requested us to modify onSearchSubmit to take an argument (event) which led to 'the most common bug' for react developers.

The render() function in our component must be an anonymous function now that it takes a variable.
i.e. now onSubmit={} requires more than a function definition, it needs to be encapsulated in an anonymous function lest it only execute at runtime.

<Search value={searchTerm}
        onChange={this.onSearchChange}
        onSubmit={(event) => {this.onSearchSubmit(event)}}>search</Search>

It would be beneficial to remind new programmers at this stage to change this code, as the previous page in the physical book instructs them to rewrite onSearchSubmit in the render() function away from proper usage:

<Search value={searchTerm}
        onChange={this.onSearchChange}
        onSubmit={this.onSearchSubmit}>search</Search> // This won't fly, but the book says to write it.

from the-road-to-learn-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.