Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!