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

152
Vistas
How to call a variable from a react function in a file to another function in a different file

On building a podcast with reactjs framework I got hooked up some where. Since on building the page header I made each header part to be a component. Below are some snippets for that:

Searchform.js

import React, {useState} from 'react';
import './searchForm.css';
import Data from '../../../tracks/tracks.json'

export default function SearchForm() {
    const [query, setQuery] = useState("");
    return ([(<div>
            <form className="no_submit mx-5">
                <input onChange={(event) =>
                    setQuery(event.target.value)}
                       className="no_submit col-xs-4 px-5 input-sm"
                       type="search"
                       placeholder="Search podcasts..."
                />
            </form>
            {Data.filter((pod) => {
                if (query === "") {
                    return pod;
                } else if (
                    pod.title.toLowerCase().includes(
                        query.toLowerCase()
                    )
                ) {
                    return pod;
                }
                return null;
            }).map(
                (pod, index) =>
                    (
                        <div key={index}>
                            <p>{pod.title}</p>
                            <p>{pod.fileUrl}</p>
                        </div>
                    )
            )}
        </div>)]
    );
}

playlist.js

import './searchForm.css';
import Data from '../../../tracks/tracks.json'

export default function SearchForm() {
    const [query, setQuery] = useState("");
    return ([(<div> ...

Question:

How can I get the value of the input field from the searchform.js into the playlist.js

No working:

Declaring the variable out of the class before calling it renders an error message.

about 4 years ago · Juan Pablo Isaza
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