-1

I have this code in my application.

const queryString = require('query-string');
const parsed = queryString.parse(location.search);
return this.docListingService.getPacks(parsed.policy).then(packs => {
    this.setState({ isLoading: false, packs });
    return packs;
}).catch((error) => {
    this.loggingService.logError('Error returning Docs ' + error);
    this.setState({ errorOccured: true});
});

It doesn't work because location.search is undefined.

I can see that location is http://localhost:3000/ which is where this application is running. How can/should this be set?

runnerpaul
  • 5,942
  • 8
  • 49
  • 118

2 Answers2

1

You can't using dot notaion on strings!

Based on this You can try this (if you are using react hooks), first of all define location: const location = useLocation();

1

Try to investigate a little bit:

Location search is a funtion that returns the queryString of the url. you dont have a queryString in your URL ..your/whole/url?queryStringOverHere=something

guiwme5
  • 712
  • 6
  • 10