Rendering query string variables in React [duplicate]

I’m trying to display a query string in my React component.

http://localhost:3000/results?s=hello

Does anyone know why this isn’t working?

function Results() {
    var query = new URLSearchParams(this.props.location.search);
    var greeting = query.get('s')
    
    return (
        <div>{greeting}</div>
    )

}

export default Results;

When I replace it with the following it works, but I don’t want to hardcode the greeting.

function Results() {
    var greeting = 'Hello'
    
    return (
        <div>{greeting}</div>
    )

}

export default Results;

Thank you