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

162
Views
Share the useState between two adjacent components in React

I need help, is there any possible way to send the useEffect submittedInput from search.js to AllThemeContext.js to use it as value of Provider ? Both are in two separated files. Please I asked this question and none has responded please help me. I don't want to move the search to context i want them to stay in separated files.

/Search js/

/*Import*/
import React, { useState } from "react";
import "./Search.scss";
/*Component*/
const Search = () => {
  const [input, setInput] = useState("");
  const [submittedInput, setSubmittedInput] = useState("");

  const onFormSubmit = (e) => {
    e.preventDefault();
    setInput("");
  };

  return (
    <>
      <div className="Search">
        <form onSubmit={onFormSubmit} className="Search__form">
          <input
            value={input}
            onChange={(e) => setInput(e.target.value)}
            type="text"
            placeholder="&#xF002; Title, companies, expertise, or benefits"
            style={{ fontFamily: "Poppins, FontAwesome" }}
          ></input>
          <button onClick={() => setSubmittedInput(input)}>Search</button>
        </form>
      </div>
    </>
  );
};

export default Search;

AllThemeContext:

import React, { createContext, useState } from "react";
export const AllContext = createContext();

const AllContextProvider = (props) => {
  const [input, setInput] = useState();
  const [numbs, setNumbs] = useState(1);
  return (
    <AllContext.Provider value={{ input, numbs }}>
      {props.children}
    </AllContext.Provider>
  );
};

export default AllContextProvider;
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!