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

226
Vistas
How to fetch console date on webpage react axios

How to fetch api data on web page using axios in react js,

Expected :

Via GET api call i get some response in console , now i want to print that console data in the web page

import React, { Component } from 'react'
import axios from 'axios'
// import { data } from 'jquery'
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()
        
        axios
        .get(`http://127.0.0.1:8000/hvals_hash?key=${this.state.key}`)
        .then(response => {
            console.log(response.data)
        })
        .catch(error => {
            console.log(error)
        })
    }

    render() {
        const { key } = this.state
        
        return (
            <center><div>
                <form onSubmit={this.submitHandler}>
                    <div>
                        <h2> DATE PICKER</h2><br></br>
                        <input
                            type="text"
                            name="key"
                            value={key}
                            onChange={this.changeHandler}
                        />
                        
                    </div>
                    <br></br>
                    <button type="submit">Submit</button>
                </form>
            </div></center>
        )
    }
}

export default PostForm

NOTES :

data in the console like Array data (24) 

["["/home/fraction/FastAPI/videos/video1.mp4", "/home/fraction/FastAPI/videos/video2.mp4", "/home/fraction/FastAPI/videos/video3.mp4", "/home/fraction/FastAPI/videos/video4.mp4", "/home/fraction/FastAPI/videos/video5.mp4"]

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

0

You need to store your api response in some state

  • take a state maybe name myVideoUrl
  • setState this with your response from api
  • then you need to import video player here so this component become parent and your video player component will be a child then pass this state myVideoUrl to your child component
import React, { Component } from 'react'
import axios from 'axios'
// import { data } from 'jquery'
class PostForm extends Component {
constructor(props) {
    super(props)

    this.state = {
        key: '',
        myVideoUrl: ''
    }
    console.log(this.state)
}

changeHandler = e => {
    this.setState({ [e.target.name]: e.target.value })
}

submitHandler = e => {
    e.preventDefault()

    axios
        .get(`http://127.0.0.1:8000/hvals_hash?key=${this.state.key}`)
        .then(response => {
            console.log(response)
            this.setState({ myVideoUrl: response })
        })
        .catch(error => {
            console.log(error)
        })
}
render() {
    const { key } = this.state

    return (
        <center><div>
            <form onSubmit={this.submitHandler}>
                <div>
                    <h2> DATE PICKER</h2><br></br>
                    <input
                        type="text"
                        name="key"
                        value={key}
                        onChange={this.changeHandler}
                    />

                </div>
                <br></br>
                <button type="submit">Submit</button>
            </form>
        //im assuming your child component here
            <MyVideoPlayer url={this.state.myVideoUrl} />
        </div></center>
    )
}}
export default PostForm

after this you can access this.props.url in your child component

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