Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda