Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
How to pass paramter in react js URL to get data from api

I created a simple date picker user interface in react js, picking a date from the drop-down, my fast API connected with Redis, now how to store data in a variable and use that variable in URL to GET data from API

    import React, { Component } from 'react'
    import axios from 'axios'
    class PostForm extends Component {
        constructor(props) {
            super(props)
    
            this.state = {
                key: '',
                
            }
            console.log(this.state)
        }
    
        changeHandler = e => {
            this.setState({ [e.target.name]: e.target.value })
        }
    
        submitHandler = e => {
            e.preventDefault()
            console.log(this.state)
            axios
                .get('http://127.0.0.1:8000/hvals_hash?key=30/8/21')
                .then(response => {
                    console.log(response)
                })
                .catch(error => {
                    console.log(error)
                })
        }
    
        render() {
            const { key } = this.state
            return (
                <div>
                    <form onSubmit={this.submitHandler}>
                        <div>
                            <input
                                type="text"
                                name="key"
                                value={key}
                                onChange={this.changeHandler}
                            />
                        </div>
    
                        <button type="submit">Submit</button>
                    </form>
                </div>
            )
        }
    }
    
    
    
    export default PostForm

In that URL I want to pass as a parameter to get particular data or selected data by the user. How to do that?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You define and store the key in your component's store, so just edit the URL address and place the key on it.

submitHandler = e => {
  e.preventDefault()
  
  axios
    .get(`http://127.0.0.1:8000/hvals_hash?key=${this.state.key}`)
    .then(response => {
      console.log(response)
     })
    .catch(error => {
      console.log(error)
    })
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda