react-streams icon indicating copy to clipboard operation
react-streams copied to clipboard

scanPlans example only works once

Open JaimeStill opened this issue 6 years ago • 1 comments

props.url in handleInput is available on the first search, but in subsequent searches, it is listed as undefined.

This behavior occurs on both your codesandbox.io examples, and when trying to follow along with examples in Stackblitz.

Here's an example screenshot logging the URL whenever two searches are attempted:

image

I'm pretty new to React, so I'm not sure what would be causing this, but thought you might want to know about this behavior.

JaimeStill avatar Aug 26 '18 17:08 JaimeStill

I was able to figure out a fix! The url property needs to be included in the map call piped into the ajax request, as well as the initial map whenever term.length < 2:

const handleInput = pipe(
  pluck('target', 'value'),
  debounceTime(250),
  distinctUntilChanged(),
  /*
    map a fn which returns an object, fn, or Observable (which returns an
    object, fn, or Observable)
  */
  map(term => props => {
    console.log('props', props);
    // updated
    if (term.length < 2) return { people: [], term: "", url: props.url }
    return ajax(
      `${props.url}?username_like=${term}`
    ).pipe(
      pluck('response'),
      map(people => ({
          // updated
          url: props.url,
          term,
          people: people ? people.slice(0, 10) : []
      }))
    );
  })
);

JaimeStill avatar Aug 26 '18 18:08 JaimeStill