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

142
Views
¿El elemento principal useEffect se activa si el estado del elemento principal cambia en el componente secundario?

Estoy tratando de pasar el setter del componente principal al componente secundario, pero cuando invoqué al setter, no activó el useEffect del padre.

 const Product = ({ product }) => { return ( <div className="border border-black rounded border-2 p-5 flex m-5"> <div className="w-1/3"> <p>Name: <span>{product.name}</span></p> </div> <div className=""> <p>Price: <span>{product.price}</span></p> </div> </div> ) } const CreateForm = ({addProduct}) => { //renders a POST form for adding product when submit is clicked it triggers //addProduct } const Main () => { const [products, setProducts] = useState([]) const fetchData () => { fetch("get/products") .then(response => response.json()) .then(data => setProducts(data)) } useEffect(() => { console.log("useEffect triggered!") fetchData(); }, []) const addProduct = (product) => { const updatedProducts = [...products, product] setProducts(updatedProducts) } const data = products.map(product => <Product product={product}/>) return ( <div className="m-10"> <CreateForm addProduct={addProduct}/> {data} </div> ) }

Cuando se hace clic en el botón Enviar, realiza una solicitud POST creando un producto y se invoca el addProduct

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!