Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scanPlans example only works once #14

Open
JaimeStill opened this issue Aug 26, 2018 · 1 comment
Open

scanPlans example only works once #14

JaimeStill opened this issue Aug 26, 2018 · 1 comment

Comments

@JaimeStill
Copy link

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
Copy link
Author

JaimeStill commented Aug 26, 2018

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) : []
      }))
    );
  })
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant